I have a pipeline which runs another bunch of jobs inside a stage:
node{
stage("building_other_components") {
build 'job1'
build 'job2' }}
How can I recover the build number or URL of these jobs? I just want to send the URL by mail ( Example: http://localhost:8080/job/job1/25/last-changes/ , I will add the last-changes part)
Thanks,
A trigger lets us execute a job on an event occurrence. This event is called a trigger. To see the list of build triggers, we need to login to Jenkins and click on any item already created and click on configure. Trigger build remotely: The job is usually triggered by accessing a specified URL. This is convenient for scripts.
If you want to know how long a job takes to run, then you need to get down to the build level. To get build metadata, you need to call get_build_info (). This method takes in the job name and the build number and returns the metadata as a dictionary. You can do a lot more with the Python Jenkins package.
As shown in the above figure, different types of Jenkins Jobs are: (i) Freestyle Project: This is a regular and popular job in Jenkins which allows us to build our project, integrate our builds or source code management with Jenkins, poll the SCM, create triggers, and many more. (ii) Maven Project: Enables us to build our maven projects.
To get build metadata, you need to call get_build_info (). This method takes in the job name and the build number and returns the metadata as a dictionary. You can do a lot more with the Python Jenkins package.
As long as you wait for the run to complete (defaults true
), you can access the result from the returned value of the build
step. The returned value is of the type of org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper
(Javadoc, source code). You can see the help for the build
step by using the snippet generator.
Using part of your code as an example:
final job1Result = build('job1')
echo "Job 1 number: ${job1Result.number}"
final job2Result = build('job2')
echo "Job 2 number: ${job2Result.number}"
This uses the getNumber()
method to get the number of the executed run.
In case of it is useful for someone:
def job1_props = build 'job1'
def j1EnvVariables = job1_props.getBuildVariables();
print "${j1EnvVariables}"
inside the j1EnvVariables the environment variable BUILD URL is present: BUILD_URL:http://localhost:8080/job/job1/26/ and the BUILD_NUMBER:26 and another useful information to access:
def path1 =" ${j1EnvVariables1.BUILD_URL}last-changes/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With