List Promoted Marked Build#

Visto 5 veces
Saltar al primer mensaje no leído

avinash....@gmail.com

no leída,
26 may 2017, 16:09:0326/5/17
a 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

no leída,
26 may 2017, 18:09:3226/5/17
a 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

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos