4
votes

I have a Jenkins build job. It has section for shell command where I read "version" of the current application that i am building. Now, i want to set the Jenkins custom variable "VERSION" with the "version" in the same shell command section. I need to pass this value as parameter to some other job being triggered after successful build of this job.

enter image description here

Now, I would pass the Jenkins variable VERSION to some other Job.

enter image description here

Please suggest how can I do this.

2
checkout this stackoverflow.com/questions/9704677/…, looks like similar to your query check for 2nd and 4th solution, might help - anshul Gupta
my use case is to create a variable inside one and then pass it to another. I am not able to create the custom variable in the batch command section that i can pass in the parameterized way to another. - Rahul Mohan

2 Answers

3
votes

Use EnvInject Plugin to inject runtime variables into Jenkins build process so that you can use in other build steps or you can pass it on to other Job's as input parameter.

3
votes

I could get some clue from Suresh's answer. I did the following steps and it worked well.

Step 1: Install Plugin “EnvInject Plugin”.

enter image description here

Step 2: Set the custom env variable and store that in env.properties

enter image description here

Step 3: Add POST Build Action, “Trigger parameterized build on other projects”

enter image description here

Step 4: Add the variables that the Post Build Job is expecting: Here the BUILD_NUMBER and FILE_VERSION are two parameterized variables that the next Job is expecting. FILE_VERSION is passed as parameters from properties file which was stored in STEP 2.

enter image description here