在Jenkins中为单个活动选择参数添加多个引用参数

t8e9dugd  于 11个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(181)

我试图为一个活动参数添加多个React参数。但是当我在Jenkins Pipeline中实现它时,第二个React参数正在回退脚本。但是当我试图通过Jenkins Console做同样的事情时,它正在工作。那么,为什么它不通过管道工作?任何帮助都将不胜感激。

管道脚本

pipeline {
    

 parameters{
    
                activeChoice choiceType: 'PT_SINGLE_SELECT', 
                filterLength: 1, 
                filterable: false, 
                name: 'Env',
                randomName: 'choice-parameter-25251019944217', 
                script: 
                    groovyScript(
                        fallbackScript: [
                            classpath: [], 
                            oldScript: '', 
                            sandbox: true, 
                            script: 'return[\'Could not get Env\']'],
                            script: [classpath: [], 
                            oldScript: '', 
                            sandbox: true, 
                            //script: 'return'+func1()
                            script: 'return[\'demo\',\'tenant\']'
                        ]
                    )
               
                reactiveChoice choiceType: 'PT_SINGLE_SELECT',
                filterLength: 1, 
                filterable: false, 
                name: 'machines', 
                randomName: 'choice-parameter-37944444770435', 
                referencedParameters: 'Env', 
                script: 
                    groovyScript(
                        fallbackScript: [
                            classpath: [], 
                            oldScript: '', 
                            sandbox: true, 
                            script: 'return[\'error\']'], 
                            script: [classpath: [], 
                            oldScript: '', 
                            sandbox: true, 
                            script: '''if(Env.equals('tenant')){
return[\'tenant1\',\'tenant2\']
}
else if(Env.equals(\'demo\')){
return[\'demo1\',\'demo2\']
}'''
                        ]
                    )
                
                reactiveChoice choiceType: 'PT_SINGLE_SELECT',
                filterLength: 1, 
                filterable: false, 
                name: 'servers', 
                randomName: 'choice-parameter-37944444770435', 
                referencedParameters: 'Env', 
                script: 
                    groovyScript(
                        fallbackScript: [
                            classpath: [], 
                            oldScript: '', 
                            sandbox: true, 
                            script: 'return[\'error\']'], 
                            script: [classpath: [], 
                            oldScript: '', 
                            sandbox: true, 
                            script: '''if(Env.equals('tenant')){
return[\'dotnet\',\'php\']
}
else if(Env.equals(\'demo\')){
return[\'nodejs\',\'php\']
}'''
                        ]
                    )
    }

  agent any
  stages {
      stage ("Example") {
        steps {
         script{
          echo 'Hello'
          echo "${params.Env}"

        } }
      }
  }

字符串

Jenkins控制台问题


的数据

bweufnob

bweufnob1#

我把我的参数移到属性部分。现在它可以工作了。

properties([
    parameters([
        [$class: 'ChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT', 
            description: 'Select the Env Name from the Dropdown List', 
            filterLength: 1, 
            filterable: true, 
            name: 'Env', 
            randomName: 'choice-parameter-5631314439613978', 
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: true, 
                    script: 
                        'return[\'Could not get Env\']'
                ], 
                script: [
                    classpath: [], 
                    sandbox: true, 
                    script: 
                        'return[\'demo\',\'tenant\']'
                        
                ]
            ]
        ], 
        [$class: 'CascadeChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT', 
            description: 'Select the Server from the Dropdown List', 
            filterLength: 1, 
            filterable: true, 
            name: 'Server', 
            randomName: 'choice-parameter-5631314456178619', 
            referencedParameters: 'Env', 
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: true, 
                    script: 
                        'return[\'Could not get Environment from Env Param\']'
                ], 
                script: [
                    classpath: [], 
                    sandbox: true, 
                    script: '''if(Env.equals('tenant')){
return[\'tenant1\',\'tenant2\']
}
else if(Env.equals(\'demo\')){
return[\'demo1\',\'demo2\']
}'''
                ]
            ]
        ],
    [$class: 'CascadeChoiceParameter', 
                choiceType: 'PT_SINGLE_SELECT', 
                description: 'Select the Server from the Dropdown List', 
                filterLength: 1, 
                filterable: true, 
                name: 'Server2', 
                randomName: 'choice-parameter-5631314456178619123', 
                referencedParameters: 'Env', 
                script: [
                    $class: 'GroovyScript', 
                    fallbackScript: [
                        classpath: [], 
                        sandbox: true, 
                        script: 
                            'return[\'Could not get Environment from Env Param\']'
                    ], 
                    script: [
                        classpath: [], 
                        sandbox: true, 
                        script: '''if(Env.equals('tenant')){
return[\'dotnet\',\'php\']
}
else if(Env.equals(\'demo\')){
return[\'nodejs\',\'php\']
}'''
                    ]
                ]
            ]
    ])
])

pipeline {
  agent any
  stages {
      stage ("Example") {
        steps {
         script{
          echo 'Hello'
          echo "${params.Env}"
          echo "Crossed param validation"
        } }
      }
  }
}

字符串

相关问题