0
votes

I'm using Jenkins to deploy and test our software. Our software has a unique build number.

I created a job "unique build number". This job basically does nothing but increment the build number.

The Idea is that all of my actual build jobs trigger the unique build number job (and block until the build number increment is completed). The challenge here is that i need to pass the actual build number to some further downstream jobs as parameter (I'm using jenkins parametrised trigger plugin).

I thought about extracting the actual build number using a groovy script. I tried to excevute this groovy script

import jenkins.model.Jenkins

def jobname = "unique_build_number"
def job = Jenkins.instance.getItemByFullName(jobname)
def build = job.getLastBuild()

But this always gives me

java.io.IOException: Cannot run program "groovy" (in directory "/Users/ci-slave/jenkins/workspace/Test_Get_Build_Number"): error=2, No such file or directory

How would you get the build number from anther jenkins job. It doesn't have to be a groovy solution. I'm completely open to suggestions :)

1

1 Answers

1
votes

In Groovy Postbuild Step you can do something like:

def build = manager.build.number

In order to access the job you can do

def job - build.parent