List Promoted Marked Build#

5 views
Skip to first unread message

avinash....@gmail.com

unread,
May 26, 2017, 4:09:03 PM5/26/17
to Jenkins Users
Hi Folks,
I have Job-1 and Job-2. 

In Job-2 I am trying to get the latest Promoted Build marked Build# for a Job-1. So i am trying this with Grrovy script. Can any one help me to achieve this.

I have below script which gives me all the build# for a job. But i want only those build which are marked as Promoted.

import hudson.model.*

BUILD_JOB_NAME = "sandbox/Job-1"

def getJobs() {
return Jenkins.instance.getAllItems(AbstractProject.class)
}

def getBuildJob() {
    def buildJob = null
    def jobs = getJobs()
    (jobs).each { job ->
       if (job.fullName == BUILD_JOB_NAME) {
            buildJob = job
        }
    }
    return buildJob
}

def getAllBuildNumbers(Job job) {
    def buildNumbers = []
    (job.getBuilds()).each { build ->
        buildNumbers.add(build.number)
    }
    return buildNumbers
}

def buildJob = getBuildJob()

return getAllBuildNumbers(buildJob) 

Victor Martinez

unread,
May 26, 2017, 6:09:32 PM5/26/17
to Jenkins Users
Hi there,



So, just a snippet to illustrate the above:

Jenkins.instance?.getItemByFullName('test')?.
    getBuilds()?.
    findAll { it.getAction(hudson.plugins.promoted_builds.PromotedBuildAction).getPromotions() }?.
          each {
println it
}


Cheers

Reply all
Reply to author
Forward
0 new messages