I am struggling to figure out some sample example to trigger hudson.model.Job from plugin:
private void triggerPipelineJobs(){
for (Job<?,?> job : Jenkins.getInstance().getAllItems(Job.class)) {
System.out.println("job is : " + job.getName());
//how to trigger this jenkins pipeline job
}
}
Remote Job Name or full URL. The name or URL of the job on the remote Jenkins host which you would like to trigger. If the full job URL is specified the URL of the remote Jenkins host configured above will be ignored. The max concurrent connections to the remote host, default is 1, max is 5.
Key Takeaways: 1 A job is a runnable task that Jenkins controls to achieve a required objective. 2 Also, we can create a new job by clicking on “New Item” in the Jenkins dashboard. 3 We need to configure our jobs according to our requirements for making it fully runnable. More items...
There is also a Parameterized Remote Trigger Plugin in case you want to trigger a build on a different/remote Jenkins Master. The parameters section can contain a combination of one or more of the following: Subversion revision: makes sure the triggered projects are built with the same revision (s) of the triggering build.
It is possible to override/rewrite the 'Trust all certificate'-setting for each Job separately. Setting this checkbox to 'true' will result in accepting all certificates for the given Job. If your remote Jenkins host has a self-signed certificate or its certificate is not trusted, you may want to enable this option.
To run all Jenkins jobs (including pipelines), I use the following:
import hudson.model.*;
// get all jobs
jobs = Hudson.instance.getAllItems(Job.class);
// iterate through the jobs
for (j in jobs) {
// first check, if job is buildable
if (j instanceof BuildableItem) {
// run that job
j.scheduleBuild();
}
}
I think the part you are looking for is the scheduleBuild()
method which you could call on your job
variable in your for loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With