Mannie
Mannie

Reputation: 1664

retaining $PATH between processes in cloudbees jenkins

Jenkins on Cloudbees - I have 2 shell scripts:

1 - Sets $PATH to include

/scratch/jenkins/addons/ruby/ruby-2.0.0-p247-x86_64/bin

2 - echos $PATH

From script 1:  + /scratch/jenkins/addons/ruby/ruby-2.0.0-p247-x86_64/bin:/scratch/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodeJS_Install/bin:/opt/jdk/latest/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/opt/maven/latest/bin:/opt/ant/latest/bin:/opt/android/android-sdk-linux/tools:/opt/gradle/latest/bin:/home/jenkins/bin:/opt/jdk/jdk.latest/bin
+ sh/echo_path.sh
From script 2:  + /scratch/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodeJS_Install/bin:/opt/jdk/latest/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/opt/maven/latest/bin:/opt/ant/latest/bin:/opt/android/android-sdk-linux/tools:/opt/gradle/latest/bin:/home/jenkins/bin:/opt/jdk/jdk.latest/bin

As you can see script 2 has lost the ruby entry made by script 1 to $PATH. Why does this happen and can it be stopped as it affects the build steps further down the line?

Upvotes: 0

Views: 143

Answers (2)

Jesse Glick
Jesse Glick

Reputation: 25461

You can use the EnvInject plugin for the originally requested purpose. From its wiki:

To inject variables as a build step obtained from a file filled in by a previous build step

Upvotes: 1

recampbell
recampbell

Reputation: 1247

I think the best thing to do is use the envinject plugin to set that environment variable for the entire build. Shell script build steps are just regular shell scripts. They can't export environment variables to their parent process.

Upvotes: 0

Related Questions