0

I need to read some vars created inside another job. Easier to be explain with pseudo code: my job:

{
build job:"create cluster" //this job will create some vars (cluster_name)
//used this var from my job
echo "${cluster_name}"
}

The best will be with declarative pipelines but I can always use script {}

Guel135
  • 750
  • 7
  • 26

1 Answers1

4

Firstly in your create cluster job you need to put that variable into environment variable. You can do it this way

//create cluster Jenkinsfile
env.CLUSTER_NAME = cluster_name

Then in your upstream job you can receive that variable using a result of build step.

def result = build job: 'create cluster'
echo result.buildVariables.CLUSTER_NAME 
Vitalii Vitrenko
  • 9,763
  • 4
  • 43
  • 62