如果工作是org.jenkinsci.plugins.workflow.job.WorkflowJob,则获取列表分支

时间:2019-03-26 10:32:18

标签: jenkins groovy jenkins-pipeline jenkins-groovy

我如何获得每个工作的列表分支URL?我只需要选择org.jenkinsci.plugins.workflow.job.WorkflowJob作业,并显示branch和url。

import com.cloudbees.hudson.plugins.folder.Folder

def folderName = "test"

def allJobs= hudson.model.Hudson.getInstance().getItems()

for(int i=0; i<allJobs.size(); i++){
def job = allJobs[i]

if(job instanceof hudson.model.Project && job .getLastBuild() != null ){
 processJob(job)
}else if(job instanceof Folder){
 processFolderByName(job)
 }
}

void processFolderByName(Item folder){
 if(folder.getFullName().contains(folderName))
  processFolder(folder)
}

void processFolder(Item folder){
 folder.getItems().each{
 if(it instanceof com.cloudbees.hudson.plugins.folder.AbstractFolder){
  processFolder(it)
 }else{
  processJob(it)
 }
}
}

void processJob(Item job){
 if (job.getClass().toString().contains('org.jenkinsci.plugins.workflow.job.WorkflowJob')){
  println  job.getFullName() }
}

0 个答案:

没有答案