Let’s say you are running a freestyle project in jenkins and you need a variable to use between building steps. One way is to install and use different plugins to give you the option to add custom global variables. However, there is an alternative by using linux bash commands without any further installations. (this assumes that jenkins is running on linux. Same can be applied to windows with the appropriate syntax change)

Inside a jenkins freestyle project, each “Execute Shell” box works as an individual bash script running in the workspace. It not only works for running arbitrary commands:

but also to write a full bash script:

You can then create a variable in one shell step, save it as text in the workspace and open it later in a different step using native bash:

very useful when you need unique variables or identifiers per run, with multiple steps doing different stuff.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s