Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass parameter from jenkins parameterized build to windows batch command

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

like image 645
daxu Avatar asked Jun 26 '14 12:06

daxu


1 Answers

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.

like image 63
Slav Avatar answered Sep 21 '22 21:09

Slav