11

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!

FotisK
  • 1,055
  • 2
  • 13
  • 28

1 Answers1

23

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

Community
  • 1
  • 1
Bruno Lavit
  • 10,184
  • 2
  • 32
  • 38
  • I did read this post, but I couldn't follow and get it working for my issue. Sorry, my Jenkins knowledge is only basic stuff. – FotisK Jun 19 '15 at 17:09
  • 1
    @user3458191 the answer Bruno provided is the correct one. In short, you `echo` the variable value into the properties file, then in the **same** job, you load the properties file with "EnvInject" plugin. At that points, it becomes available to all subsequent build steps, so you can use it with "Predefined parameters" just like you described. What exactly is not working for you with that solution? – Slav Jun 19 '15 at 17:31
  • I've updated my answer with some screen copies, please confirm it solves your issue and please vote for my answer :) – Bruno Lavit Jun 22 '15 at 07:11
  • The answer does solve the issue but not in the way i would like, without a property file! – FotisK Jun 22 '15 at 21:35