Check a conditional build statement during build

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

and I followed that from a pattern outlined in Conditional import not working

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

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

Any hints (or PR) is appreciated.

Thanks in advance.

The if: clause for conditional builds/stages/jobs should be specified at build, stage or job level as specified in the documentation 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 in Bash (or other) code in your scripts. E.g. to check if it’s a cron job:

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

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

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.

1 Like

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).