string 如何使用可选复选框向 Jenkins 添加字符串参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25284030/
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 add String parameter to Jenkins with optional checkbox
提问by Alex Brodov
I'm trying to add a String parameter to my jenkins build, but i can't find an option to make it optional, on the Jenkins WIKI i found a screeshot and there was an option to make it optional: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build.
我正在尝试向我的 jenkins 构建添加一个字符串参数,但我找不到使它成为可选的选项,在 Jenkins WIKI 上我找到了一个 screeshot 并且有一个选项可以使它成为可选:https://wiki .jenkins-ci.org/display/JENKINS/Parameterized+Build。
回答by Slav
All parameters are "optional". Unless it's a Validating String Parameter, Jenkins doesn't care what value you've entered or if you've entered anything at all.
所有参数都是“可选的”。除非它是Validating String Parameter,否则Jenkins 并不关心您输入了什么值,或者您是否输入了任何内容。
The only thing that cares about the parameters is your job implementation, i.e. your scripts (bash) and other action that are configured to use the parameter.
唯一关心参数的是您的作业实现,即您的脚本 (bash) 和其他配置为使用参数的操作。
If your parameter is called "Param", you can access it's value through:
如果您的参数名为“ Param”,您可以通过以下方式访问它的值:
${Param}
on Linux.%Param%
on Windows.
${Param}
在 Linux 上。%Param%
在 Windows 上。
Edit to answer comments:
To pass params from a "parent" build to the downstream builds, depends on how you trigger the downstream builds. If you are using Call/Trigger Parameterized Buildplugin (which you should be), then there is a simple option to pass parent parameters to downsteam builds. They will be available in child builds through the same param name, like ${Param}
in the above example.
编辑以回答评论:
将参数从“父”构建传递到下游构建,取决于您如何触发下游构建。如果您正在使用调用/触发参数化构建插件(您应该使用),那么有一个简单的选项可以将父参数传递给下游构建。它们将通过相同的参数名称在子构建中可用,${Param}
如上例所示。
If you are triggering it some other way, there are a number of workarounds, mainly through storing them in a property file and then loading that property file in child build through EnvInjectplugin
如果您以其他方式触发它,有许多解决方法,主要是通过将它们存储在属性文件中,然后通过EnvInject插件在子构建中加载该属性文件
回答by Technext
Just provide a default value to the string parameter. As long as you do not change it, it's optional. You will simply have to check whether the parameter is set to the default and depending on the same, you can decide the course of action.
只需为字符串参数提供一个默认值。只要你不改变它,它就是可选的。您只需检查该参数是否设置为默认值,并根据此参数决定操作过程。
Check the option 'This build is parameterized'. Now select 'String Parameter'. To access the parameter from bash script, you just have to check the value of the variable that you assign to 'Name' textbox as shown in the fig.
选中“此构建已参数化”选项。现在选择“字符串参数”。要从 bash 脚本访问参数,您只需检查分配给“名称”文本框的变量的值,如图所示。
echo "Country selected is $Country"