Java 如何使用 Jenkins 参数化构建?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18991273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Jenkins parameterized builds?
提问by
Jenkins allows you to parameterize builds, but I can't figure out how to actually make use of it:
Jenkins 允许您参数化构建,但我不知道如何实际使用它:
Say I would normally kick my Ant build off from the command-line like so:
假设我通常会像这样从命令行启动 Ant 构建:
ant -buildfile /path/to/my/build.xml -DpackageType=jar package
This would invoke the build.xml
's package
target, and make a property named packageType
available to it, with a value of jar
.
这将调用build.xml
的package
目标,并使名为 的属性对其packageType
可用,值为jar
。
I'm assuming that in the screenshot above, the Namefield is where I would specify packageType
, but what about the value?
我假设在上面的屏幕截图中,Name字段是我要指定的地方packageType
,但是值呢?
- If Jenkins wants me to specify a Default Valuefor the property, then where do I specify the value that my project is using? For instance, I might want a Default Valueof
war
, but have this Jenkins job pass in a value ofjar
(to override the default). - Also, what does Jenkins mean by "...allows the user to save typing the actual value." Which user? Where would you type the value anyways?
- 如果 Jenkins 希望我为属性指定默认值,那么我应该在哪里指定我的项目正在使用的值?举例来说,我可能需要一个默认值的
war
,但有值这个詹金斯工作通jar
(覆盖默认)。 - 另外,Jenkins 的意思是“...允许用户保存输入的实际值。”哪个用户?无论如何你会在哪里输入值?
Thanks in advance!
提前致谢!
采纳答案by Harshavardhan Konakanchi
Whenever the user configures a parameterised build in Jenkins, the parameter name is taken as an environment variable
每当用户在 Jenkins 中配置参数化构建时,参数名称将作为环境变量
The user can make use of such parameters using the environment variable.
用户可以使用环境变量来使用这些参数。
For example, in your case if packageTypeis the parameter you want to pass,
例如,在您的情况下,如果packageType是您要传递的参数,
then specify the name as packageTypeand value as war
然后将名称指定为packageType并将值指定为war
You can use it in the script you required as %packageType%
(for Batch) or $packageType
(for shell)
您可以在您需要的脚本中使用它%packageType%
(对于 Batch)或$packageType
(对于 shell)
After configuring the job, whenever you click the build now button, Jenkins prompts for the parameter
配置好job后,无论何时点击build now按钮,Jenkins都会提示输入参数
When you are using file Parameter, the uploaded file will be placed into the working directory
当你使用 file 参数时,上传的文件会被放到工作目录中