Problem: I'm using a script to determine if a certain amount of jobs are in SUCCESS state. It worked fine as long as I was not using cloudbees folder plugin. I could easily get the list of projects and get the project result. But after I moved the jobs to the cloudbee folder, the jobs and therefore the job results are no longer available!
Q: Does anybody now how to get the job results with groovy from jobs which are located in a Cloudbees folder?
def job = Jenkins.instance.getItemByFullName('foldername/jobname');
Folder plugin provides the getItems()
method which can be used to get all immediate items (jobs/folders) under a folder.
folder.getItems()
Check this link to traverse across all the folders in Jenkins.
Displaying the code snippet below,
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
import hudson.scm.*
import hudson.tasks.*
import com.cloudbees.hudson.plugins.folder.*
jen = Jenkins.instance
jen.getItems().each{
if(it instanceof Folder){
processFolder(it)
}else{
processJob(it)
}
}
void processJob(Item job){
}
void processFolder(Item folder){
folder.getItems().each{
if(it instanceof Folder){
processFolder(it)
}else{
processJob(it)
}
}
}
来源:https://stackoverflow.com/questions/21728058/cloudbees-groovy-jobs-folders-how-to-determine-the-job-result-if-the-job-is