Matt - sanemat
Matt - sanemat

Reputation: 5618

Jenkins scheduled build Triggers with environment variable?

I want to build periodically with environment variable in jenkins:

#pseudo setting
H 17 * * * BUILD_FOR=gist-mail TOKEN_GIST_MAIL=some_token
H 17 * * * BUILD_FOR=pollyanna TOKEN_POLLYANNA=anothor_token
H 17 * * * BUILD_FOR=fenix-knight TOKEN_FENIX_KNIGHT=alternative_token

These variables do not change dynamically, given in advance.

I got a error below:

Invalid input: "10 17 * * * BUILD_FOR=fenix-knight": line 1:12: expecting EOF, found ' '

How do I pass different environment variable to each build trigger? My work around is create each jobs.

My executing shell below:

gem install bundler
ruby -i -pe '$_.gsub! /^ruby/, "#ruby"' Gemfile
bundle
BUILD_FOR=fenix-knight bundle exec rake tachikoma:load tachikoma:fetch tachikoma:bundle tachikoma:pull_request

Upvotes: 4

Views: 8013

Answers (2)

Andy Chen
Andy Chen

Reputation: 361

Looks like your schedules are the same but you want to kick off 3 builds with different environment variables. I think on way is to first create a job with parameters. Parameters should be holding your environment variables. Then create another job with actual schedule to call your job created, in build step you use the Jenkins CLI to actually kick off the job with parameters.

Upvotes: 2

KeepCalmAndCarryOn
KeepCalmAndCarryOn

Reputation: 9075

There is a parameterized build plugin for your situation Jenkins - triggering a parameterized build has a good demonstration of how to use it and also another plugin to show the parameters which went into it.

You could also look at the multijob plugin https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin to run one underlying job with separate parameters

Upvotes: 2

Related Questions