Issue
I am starting to use Jenkins, which is a really great tool. We are using parameterized build, we define parameter such as branch name ${Branch} (e.g. dev, release, main etc).
In the build config, I can add a windows batch command, is there a way I can pass down these parameters to the batch command?
I tried to pass like "%${Branch}%" or "%Branch%", but seems not working.
Can anyone help?
Many Thanks
Solution
Using Parameterized Build, you need to define parameters. The value of these will be prompted to you when you click "Build" link.
The name of the parameters should be a plain name, preferably without spaces, like Branch
. Do not add any ${}
or %%
to definition of the parameter name.
In the build steps, like Execute Windows Batch Command, you can reference the parameter with regular batch syntax, like %Branch%
.
If you would be on a *nix machine, you would use Execute shell build step and reference the parameter with regular bash syntax, like ${Branch}
Note that even when running on Windows, a lot of Jenkins plugins themselves take the parameters in *nix syntax, however the Execute Windows Batch Command will be batch-like, i.e. %Branch%
.
So, you can try typing:
echo %Branch%
I also suggest putting just set
command on a line by itself, and it will show you all environment variables available to you during the build process, which is quite useful.
Answered By - Slav