matandked matandked - 1 year ago 117
PowerShell Question

Is it possible to execute Jenkins jobs from Powershell or Bash or Groovy scipts?

I have separated quite small Jenkins jobs.

Now I need to configure another job which depending on the selected by the user parameters (selected probably through checkboxes?) will execute some of them.

I would like to start them from Powershell or Bash or Groovy script. Is it possible?

Answer Source

If you are using Groovy in a Postbuild/pipeline step, you can start the job via the Jenkins API.

For example, something like this for parameterless builds:

Jenkins.instance.getItem("My Job").scheduleBuild(5)

And something like this for parameterized builds:

Jenkins.instance.getItem("My Job").scheduleBuild( 5, new Cause.UpstreamCause( currentBuild ), new ParametersAction([ new StringParameterValue( "My Parameter Name", "My Parameter Value" ) ]));

You can also use the Jenkins Rest API for the rest. For example, by hitting the following url:




curl -X POST JENKINS_URL/job/JOB_NAME/buildWithParameters?MyParameterName=MyParameterValue
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download