当前位置: 动力学知识库 > 问答 > 编程问答 >

cloudbees - Accessing Jenkins Job attributes from another job

问题描述:

I have a Jenkins groovy template script that is looping through a list of auxiliary models called services. Each auxiliary model has a job called reportableJob as an attribute. These "reportable jobs" all have an attribute called branch. How can I access this attribute?

Here's my general thinking:

for (i=0; i< services.size(); i++) {

def job = services[i].reportableJob

def branch = job.branch

echo "${branch}"

}

This results in the following error:

groovy.lang.MissingPropertyException: No such property: branch for class: org.jenkinsci.plugins.workflow.job.WorkflowJob

网友答案:

Got it figured out, good to know:

for (i=0; i< services.size(); i++) {
    def job = services[i].reportableJob
    def instance = com.cloudbees.hudson.plugins.modeling.impl.entity.EntityInstance.from(job)
    echo "Branch: ${instance.getValue("branch")}"
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: