为 Jenkins 中的单个主动选择参数添加多个参考参数

问题描述 投票:0回答:1

我正在尝试为单个活动参数添加多个反应参数。但是当我在 Jenkins Pipeline 中实现它时,第二个反应参数是后备脚本。但是当我尝试通过 Jenkins 控制台执行相同操作时,它正在工作。那么,为什么它不能通过管道工作呢?任何帮助将不胜感激。

管道脚本

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 控制台中的问题

jenkins jenkins-pipeline jenkins-plugins jenkins-groovy
1个回答
0
投票

我将参数移至属性部分。现在它正在工作。

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"
        } }
      }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.