Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Jenkins REST API to rebuild a build

Tags:

jenkins

I have a build in Jenkins which has failed for a temporary reason. I'd like to just re-build it. On the website I just click "rebuild" (from the rebuild plug-in), and if it is a parameterized job, I get asked if I want to keep the parameters. Importantly, the new job contains a "rebuild" link back to the original job enabling back-tracing.

How can I effect this "rebuild" from the REST API. I have code that will get a completed job, extract the parameters, and invoke a new job with those same parameters - so I've got most of the way there.

But I don't know how to establish the rebuild link so I can trace what job is a rebuild of what other job.

like image 976
Gordon Avatar asked Jul 13 '16 06:07

Gordon


People also ask

How do I rebuild a failed build in Jenkins?

To retry a Jenkins job, you can use the Naginator plugin. Simply install the plugin, and then check the Post-Build action "Retry build after failure" on your project's configuration page. If the build fails, it will be rescheduled to run again after the time you specified.

Does Jenkins have a REST API?

The jenkins-rest library is an object oriented Java project that provides access to the Jenkins REST API programmatically to some remote API Jenkins provides. It is built using the jclouds toolkit and can easily be extended to support more REST endpoints.


Video Answer


1 Answers

You can't -- the rebuild plugin does not implement a REST API (as of current version 1.25; I just checked the sources).

If your job has no parameters, then just GETing the <buildUrl>/rebuild URL should trigger a rebuild, though.

If your job does have parameters, then some more scripting will be needed to mimick what you do manually in those two steps.

like image 186
Alex O Avatar answered Oct 22 '22 08:10

Alex O