简体   繁体   English

jenkins 管道中传递的字符串参数

[英]String parameter passing in jenkins pipeline

I am developing a pipeline where in when triggered it should display the parameters and below is the code我正在开发一个管道,在触发时它应该显示参数,下面是代码

node {

stage('preparation')  {
               timeout(time:15, unit:'MINUTES') {
    id: 'userInput', message: 'preparation',
                    parameters: [
                                [$class: 'TextParameterDefinition', defaultValue: 'cicd', description: 'dev env', name: 'DEV_PROJECT'],
                               [$class: 'TextParameterDefinition', defaultValue: 'test', description: 'stage env', name: 'STAGE_PROJECT'],
                               [$class: 'TextParameterDefinition', defaultValue: 'jboss', description: 'Image Name', name: 'IMAGE_NAME'],
                             ] )

                       input message: "Is the PARAMETERS(can be visible on leftside) are correctly set for deployment?", ok: "Promote" }
echo "${DEV_PROJECT}"
echo "${STAGE_PROJECT}"
echo "${IMAGE_NAME}"
}

When i do echo its not populating the values of user input.当我回显时,它不会填充用户输入的值。
Iam getting below error.我得到低于错误。 My requirement is the user can input the DEV_PROJECT,STAGE_PROJECT and IMAGE_NAME and the values entered by him should be used in the pipeline scripts down the line in build and deploy stages.Iam getting below error我的要求是用户可以输入 DEV_PROJECT、STAGE_PROJECT 和 IMAGE_NAME 并且他输入的值应该在构建和部署阶段的流水线脚本中使用。我得到以下错误

groovy.lang.MissingPropertyException: No such property: DEV_PROJECT for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
    at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:284)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:288)

could anyone let me know how to proceed?谁能让我知道如何进行?

If you have configured your pipeline to accept parameters when it is built — Build with Parameters — they are accessible as Groovy variables inside params .如果您已将管道配置为在构建时接受参数 -使用参数构建- 它们可以作为params Groovy 变量访问。

Example : Using isFoo parameter defined as a boolean parameter (checkbox in the GUI):示例:使用定义为布尔参数的isFoo参数(GUI 中的复选框):

node {
  sh "isFoo is ${params.isFoo}"
  sh 'isFoo is ' + params.isFoo
  if (params.isFoo) {
    // do something
}

Reference: https://jenkins.io/doc/book/pipeline/getting-started/#global-variable-reference参考: https : //jenkins.io/doc/book/pipeline/getting-started/#global-variable-reference

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

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