Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't export a variable from execute shell in Jenkins to other project (with using properties file)

I have a Jenkins project with one "Execute shell" that executes some bash commands and exports one variable to the env. variables:

#!/bin/bash

...
TARGET_FULLPATH="blablabla"
export TARGET_FULLPATH

In addition, I have configured to "Post-build Actions" with:

  1. "Trigger parameterized build on other projects"
  2. "Current build parameters"
  3. "Predefined parameters" -> FULLPATH=$TARGET_FULLPATH

But, when I run this project the other project that will start as soon the first one is finished seems that it doesn't get the parameter FULLPATH at all!

At least in the "Execute shell" (of the second project) the bash script print nothing for echo $FULLPATH! Also at the "Environment Variables" of the second project the FULLPATH is not included!

Any clue what am I doing wrong?

One more thing, i can't use a properties file to store the parameters, since the two projects are running on different servers and there are restrictions on copying files between those servers!

like image 928
FotisK Avatar asked Jun 19 '15 13:06

FotisK


1 Answers

Did you have a look to this solution? Jenkins: How to use a variable from a pre-build shell in the Maven "Goals and options"

Using a shell pre-build step + the InjectEnv plugin, you should be able to solve your problem.

Update from June 22nd, I add some screen copies.

1/ Add a first "Execute shell" script to create the properties file and an "Inject environment variables" step to load the properties file:

enter image description here

2/ For the demo, I add a "post-build task" step to read the variable

enter image description here

3/ Here is the console output, it works :)

enter image description here

like image 94
Bruno Lavit Avatar answered Oct 18 '22 20:10

Bruno Lavit