Nirzari
Nirzari

Reputation: 89

How to re-run Parameterized Jenkins Job again via code (without using rebuild plugin through UI)?

I have 80 jenkins jobs which I want to re-build programmatically. All 80 were run with different set of parameters. I can see 2 approaches here for job x which is inside a view as well as folder,

  1. Use some Jenkins API to build x job just by specifying the job id(aka job_url)for x job
  2. Traverse and find out parameters of the x job and use Jenkins API to build x job using those parameters.
  3. Some Groovy Script (I have no experience writing this)

Rebuild plugin is something which essentially does 1) but I want to do the same via code. Please suggest specific solution if possible instead of generic API links. I have gone through all XML, JSON and Python API for Jenkins but there isn't one straightforward way I could find. Thanks.

Upvotes: 1

Views: 2040

Answers (1)

Nirzari
Nirzari

Reputation: 89

After trying for a while, I was able to come up with a groovy script which upon running in jenkins-server-url/script does the trick.

The script is hosted at https://github.com/nirzari/groovy-scripts/blob/master/rebuild.groovy

Upvotes: 2

Related Questions