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

时间:2017-04-30 21:46:48

标签: jenkins jenkins-plugins jenkins-pipeline jobs

我正在努力找出一些示例来从插件触发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
    }
}

1 个答案:

答案 0 :(得分:2)

要运行所有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();
  }
}

我认为您要查找的部分是scheduleBuild()方法,您可以在for循环中调用job变量。