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

孤街醉人 提交于 2019-12-06 16:00:09
Jesse Glick
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)
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!