# Check a conditional build statement during build

**URL:** <https://travis-ci.community/t/check-a-conditional-build-statement-during-build/10269>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** conditions, cron\
**Created:** [October 23, 2020, 5:12pm UTC](https://travis-ci.community/t/check-a-conditional-build-statement-during-build/10269 "2020-10-23T17:12:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![icasimpan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/icasimpan/32/5384_2.png) [@icasimpan](https://travis-ci.community/u/icasimpan)\
**Post date:** [October 23, 2020, 5:12pm UTC](https://travis-ci.community/t/check-a-conditional-build-statement-during-build/10269/1 "2020-10-23T17:12:34Z")

</div>

Hello,

I’m wondering what I’m doing wrong in this .travis.yml file and I can’t make it run from daily cron.

```
dist: bionic

language: minimal

script:
 - echo "Test if cron runs"
   if: type(TRAVIS_EVENT_TYPE) = cron

```

It’s in a public repo [https://github.com/icasimpan/travis\_test2/blob/cron\_only2/.travis.yml](https://github.com/icasimpan/travis_test2/blob/cron_only2/.travis.yml)

and I followed that from a pattern outlined in [Conditional import not working](https://travis-ci.community/t/conditional-import-not-working/7915)

Initial schedule says it will be run in a short while, see screenshot [https://snipboard.io/3CeEnz.jpg](https://snipboard.io/3CeEnz.jpg)

but after a while, it says it ran [https://snipboard.io/b4Vjyu.jpg](https://snipboard.io/b4Vjyu.jpg) but nothing was built.

Any hints (or PR) is appreciated.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 23, 2020, 5:47pm UTC](https://travis-ci.community/t/check-a-conditional-build-statement-during-build/10269/2 "2020-10-23T17:47:41Z")

</div>

The `if:` clause for conditional builds/stages/jobs should be specified at build, stage or job level as specified in [the documentation](https://docs.travis-ci.com/user/conditional-builds-stages-jobs/) rather than inside a script.  
And it’s only evaluated by Travis scheduling infrastructure before the build when forming its structure – to decide which jobs should be run.

To evaluate a condition at runtime instead, use one of the [predefined environment variables](https://docs.travis-ci.com/user/environment-variables/#default-environment-variables) in Bash (or other) code in your scripts. E.g. to check if it’s a cron job:

```auto
script:
  - if [[$TRAVIS_EVENT_TYPE == "cron"]]; then echo "This is a cron job"; fi

```

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [October 23, 2020, 6:01pm UTC](https://travis-ci.community/t/check-a-conditional-build-statement-during-build/10269/3 "2020-10-23T18:01:50Z")

</div>

First and foremost, the problem is that your configuration is not valid YAML (briefly, you are starting a definition of a new map with `if:` in the middle of an array) , and therefore will not trigger a build

> **[Travis CI - Test and Deploy with Confidence](https://travis-ci.com/github/icasimpan/travis_test2/requests)**

shows it.

On the other had, when the cron _record_ indicates it did, it just means that the process was initiated, and should be worded accordingly.

---

<div class="post-metadata">

**Author:** ![icasimpan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/icasimpan/32/5384_2.png) [@icasimpan](https://travis-ci.community/u/icasimpan)\
**Post date:** [October 23, 2020, 6:13pm UTC](https://travis-ci.community/t/check-a-conditional-build-statement-during-build/10269/4 "2020-10-23T18:13:38Z")

</div>

Thank you for pointing out @native-api.

The solution I was trying to find is actually an alternative to a shell script written just like in your illustration. It perfectly worked but after a while it suddenly stopped working.

I added debugging echo lines in my shell script and “$TRAVIS\_EVENT\_TYPE” becomes an empty string despite it being run via Travis cron.

But anyway, this is outside the scope of my original question.

Thank you as well to @BanzaiMan (in another answer).
