ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Follow publication

Returning a value from Jenkins job

Pavel Bernshtam
ITNEXT
Published in
Jun 2, 2022

--

Let’s say we have a Jenkins pipeline job, that creates a virtual machine and installs a service on it.

We will create 3 jobs — one takes a machine name and a service name as a parameter and calls a second job — to create a machine and a third job to install a service.

The third job need the machine IP to install a service, so the second job, which creates the virtual machine needs to return the machine IP.

Recently I discovered that it is possible using environment variables. After downstream job finished, we can access its variables by
b.getBuildVariables()

Jenkins file of the first, “main” job:

Jenkins file of the second, “create vm” job:

So this way we can return any number of values from downstream Jenkins job and use it in the next job in the chain!

Enjoy!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

No responses yet

Write a response