将参数从jenkins参数化的构建传递到Windows批处理命令 [英] pass parameter from jenkins parameterized build to windows batch command

查看:449
本文介绍了将参数从jenkins参数化的构建传递到Windows批处理命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Jenkins,这是一个非常好的工具.我们正在使用参数化的构建,我们定义了诸如分支名称$ {Branch}之类的参数(例如dev,release,main等).

在构建配置中,我可以添加Windows批处理命令,是否可以将这些参数传递给批处理命令?

我尝试通过%$ {Branch}%"或%Branch%",但似乎无法正常工作.

任何人都可以帮忙吗?

非常感谢

解决方案

使用参数化的版本,您需要定义参数.当您单击构建"链接时,将提示您这些值.

参数名称应为纯名称,最好不要带空格,例如Branch.请勿在参数名称的定义中添加任何${}%%.

构建步骤中,例如 Execute Windows Batch Command ,您可以使用常规的批处理语法来引用参数,例如%Branch%.

如果要在* nix机器上,则可以使用 Execute shell 构建步骤并使用常规bash语法(例如${Branch}

)引用该参数

请注意,即使在Windows上运行,许多Jenkins插件本身也会采用* nix语法来使用参数,但是 Execute Windows Batch Command 将类似于批处理,即%Branch%. /p>

因此,您可以尝试输入:
echo %Branch%

我还建议仅将set命令单独放在一行上,它将在构建过程中向您显示所有可用的环境变量,这非常有用.

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

解决方案

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.

这篇关于将参数从jenkins参数化的构建传递到Windows批处理命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆