Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: setting env variable from shell script

I have a bash script that I execute from a Jenkins job, using "execute shell". The script starts an EC2 instance and sets an host variable containing the host name of the new instance.

I would like to set the host name of the new instance (script variable: host ) to a Jenkins environment variable so that I can pass it down to a downstream job (possibly using the Build Flow plugin).

Any idea how to do so?

Thanks

like image 803
Luciano Fiandesio Avatar asked Feb 21 '13 10:02

Luciano Fiandesio


People also ask

How do I set an environment variable in shell?

You can set your own variables at the command line per session, or make them permanent by placing them into the ~/. bashrc file, ~/. profile , or whichever startup file you use for your default shell. On the command line, enter your environment variable and its value as you did earlier when changing the PATH variable.

How do I add a global variable in Jenkins?

We can set global properties by navigating to “Manage Jenkins -> Configure System -> Global properties option”.


1 Answers

I ended up using a file to propagate data between builds. The first build creates a file containing the information I need to propagate (host name of the newly created EC2 instance). The file looks like:

host.name=ec2.123.3345.amazon.com

I use the EnvInject plugin to read the file and "inject" the properties that are then available in the next build (I'm using the Build Flow Plugin to orchestrate builds).

like image 173
Luciano Fiandesio Avatar answered Sep 21 '22 03:09

Luciano Fiandesio