简体   繁体   English

以编程方式从jenkins插件触发jenkins hudson.model.Job

[英]Trigger jenkins hudson.model.Job programmatically from jenkins plugin

I am struggling to figure out some sample example to trigger hudson.model.Job from plugin: 我正在努力找出一些示例来从插件触发hudson.model.Job:

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
    }
}

To run all Jenkins jobs (including pipelines), I use the following: 要运行所有Jenkins作业(包括管道),我使用以下内容:

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. 我认为您正在寻找的部分是scheduleBuild()方法,您可以在for循环中调用您的job变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM