[英]groovy.lang.MissingPropertyException - Reading input - Jenkinsfile
Below is the Jenkinsfile(scripted pipeline) code snippet to select a Git repo in stage view:下面是在阶段视图中选择 Git 存储库的 Jenkinsfile(脚本化管道)代码片段:
userInput = input(id: 'userInput',
message: 'Do you want to build?',
parameters: [
[$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
]
)
if (userInput.Env == "repo_1") {
print 'selected repo_1'
}
requests the user to select a repository and click Proceed
请求用户选择一个存储库并单击
Proceed
On clicking Proceed
button, jenkins throws error:单击
Proceed
按钮时,詹金斯抛出错误:
groovy.lang.MissingPropertyException: No such property: Env for class: java.lang.String
Manual build is only allowed for repo_1
仅
repo_1
允许手动构建
Rest of the repositories suppose to be auto-triggered其余的存储库假设是自动触发的
Edit:编辑:
After making below changes,进行以下更改后,
node('worker_node'){
def userIdCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
def manualBuild = userIdCause.size()
stage("Auth-build") {
timeout(2) {
if (manualBuild) {
userInput = input(id: 'userInput',
message: 'Please select the repository',
parameters: [
[$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
]
)
if (userInput == "None") {
error('Error output')
}
repositoryName = 'repo_1'
}else if( !manualBuild && (repositoryName == 'repo_1')){
error('error output')
}
}
}
}
I do not get UI after clicking BuildNow
, I had to follow below process:单击
BuildNow
后我没有获得 UI,我必须遵循以下过程:
1) Why userInput.Env
gives missing property exception error? 1) 为什么
userInput.Env
给出缺少属性异常错误?
2) input()
api takes a minute to render input wizard. 2)
input()
api 需要一分钟来呈现输入向导。 Can we optimise?我们可以优化吗?
No such property: Env for class: String
- i believe that input
function already returns the value of the single input. No such property: Env for class: String
-我相信input
函数已经返回了单个输入的值。 input
definition is quite simple in your case and does not contain any code (just constants) - nothing to optimize in it. input
定义在您的情况下非常简单,并且不包含任何代码(仅是常量)-无需进行任何优化。 Look for a time consumers in other places. Provide the "Choice Type" and "Referenced parameters" within Jenkins job to see the expected output.在 Jenkins 作业中提供“选择类型”和“参考参数”以查看预期输出。 In your case Referenced parameters is "Env"
在您的情况下,引用的参数是“Env”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.