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.