iBug
iBug

Reputation: 37307

How do I determine if a build is a scheduled job in CircleCI?

I would like to decide if a build is a scheduled job from inside the build.

For example, on Travis CI my build scripts look for the $TRAVIS_EVENT_TYPE environment variable to see if its value is cron.

How should I do this on CircleCI?

Upvotes: 0

Views: 250

Answers (1)

FelicianoTech
FelicianoTech

Reputation: 4017

Use a custom environment variable (envar). While you can't set an envar directly in a workflow, you can add one to a CircleCI Context, and then attach that context to the workflow. The envar name can be whatever you want and the value whatever you want.

One example would be to create a context called nightly when an envar in it that you can then check for in a job. Here's an example:

  nightly-build:                                                                                                                                                          
    triggers:                                                                                                                                                             
      - schedule:                                                                                                                                                         
          cron: "0 0 * * *"                                                                                                                                               
          filters:                                                                                                                                                        
            branches:                                                                                                                                                     
              only: master
    jobs:
      - build:
          context: nightly

Upvotes: 1

Related Questions