简体   繁体   English

Jenkins:如何在参数化构建中设置所需的参数?

[英]Jenkins: how to make parameters required in a parameterized build?

In Jenkins is there a plugin for parameterized builds to make the parameters required?在 Jenkins 中是否有用于参数化构建的插件来制作所需的参数? The fields under the standard "This build is parameterized" option do not seem to provide that.标准“此构建已参数化”选项下的字段似乎没有提供。

Clarification: by "required" I mean that the build will not execute until the field is populated with a value.澄清:“必需”是指在该字段填充一个值之前,构建不会执行。 This would obviously preclude automated triggers.这显然会排除自动触发器。

The accepted answer is no longer valid.接受的答案不再有效。

There was a plugin that did that but is no longer maintained.有一个插件可以做到这一点,但不再维护。

There's an open bug to support it .有一个开放的错误来支持它

In the mean time what you can do is check if your parameter is present and if not throw an error like:同时,您可以做的是检查您的参数是否存在,如果不存在则抛出如下错误:

if (params.SomeParam == null) {
    error("Build failed because of this and that..")
}

This is the plugin i use to do this type of stuff: link ...这是我用来做这类事情的插件: 链接...
You can set a regular expression to validate the input against您可以设置正则表达式来验证输入

Couldn't comment to answer Miguel's question, so answering here:无法评论回答 Miguel 的问题,所以在这里回答:

To fail a build if a parameter is not set, one could do something like this:如果未设置参数,则要使构建失败,可以执行以下操作:

stage('Checkout') 
    {
        steps
        {
            checkout scm
            script 
            {
                if (params.myParam == '') { // and/or whatever condition you want
                    currentBuild.result = 'ABORTED'
                    error('myParam not set')
                }
            }
        }
    }

There's a plugin called "Validating String Parameter".有一个名为“验证字符串参数”的插件。 When you install this plugin in your project, you see an additional option of Validating String Parameter while adding parameters.当您在项目中安装此插件时,您会在添加参数时看到验证字符串参数的附加选项。 Using this option will show an additional column of Regular expression.使用此选项将显示正则表达式的附加列。 For non-empty string parameter write this inside Regular Expression field:对于非空字符串参数,在正则表达式字段中写入:

^(?!\s*$).+

This will finally make your string parameter mandatory.这最终将使您的字符串参数成为必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM