Pass parameter from jenkins command with parameterization for windows batch command

I am starting to use Jenkins, which is a really great tool. We use a parameterized assembly, we define a parameter, such as the name of the $ {Branch} branch (for example, dev, release, main, etc.).

In the build configuration, I can add the windows command command, is there a way to pass these parameters to the package command?

I tried to pass as "% $ {Branch}%" or "% Branch%", but it does not seem to work.

Can anyone help?

Many thanks

+12
cmd tfs batch-file jenkins
source share
1 answer

Using Parameterized Build , you need to define parameters. The meaning of this will be offered to you when you click the Create link.

The parameter name should be a simple name , preferably without spaces, such as Branch . Do not add ${} or %% to the parameter name definition.

In the assembly steps, for example Run the Windows command , you can refer to a parameter with regular package syntax, for example %Branch% .

If you were on a * nix machine, you would use the Execute shell build step and refer to a parameter with regular bash syntax, for example ${Branch}

Please note that even when working on Windows, many Jenkins plugins themselves accept parameters in the * nix syntax, however, the Run Windows batch command will be batch, i.e. %Branch% .

So you can try entering:
echo %Branch%

I also suggest entering only the set string into the string, and it will show you all the environment variables available to you during the build process, which is very useful.

+26
source share

All Articles