cloudbees, groovy, jobs, folders: How to determine the job result, if the job is within a cloudbees folder?

删除回忆录丶 提交于 2019-12-10 11:34:15

问题


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?


回答1:


def job = Jenkins.instance.getItemByFullName('foldername/jobname');



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!