Jenkins 管道如何使用变量中的参数运行构建作业

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

在詹金斯管道中,我想使用变量 job_path 和 job_params 运行“构建作业”。

job_path = "long/path/to/different/jobs"
job_params = [string(name: 'app_one', value: '4.8.6')]
但更多时候
job_params = "[string(name: 'app_one', value: '4.8.6'), string(name: 'app_three ', value: '1.2.4'), string(name: 'app_ten', value: '2.7.1')]"

pipeline {
    stages {
        stage('Deployment') {
            steps {
                script {
                    build job: "${job_path}", parameters: job_params
                }
            }
        }
    }
}

路径完美,但参数不行。 我收到一个错误,提示需要一个列表并提供一个字符串。

java.lang.ClassCastException: class org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep.setParameters() expects java.util.List<hudson.model.ParameterValue> but received class java.lang.String

第二个:

Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: xyz
Caused: java.lang.IllegalArgumentException: Could not instantiate {job=long/path/to/different/jobs, parameters=[string(name: 'app_one', value: '4.8.6')]} for org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep

我尝试将此参数变量转换为列表, 请建议我运行作业的最佳方式,通过带有随机数量参数的路径指向。

jenkins groovy parameter-passing pipeline
1个回答
0
投票

你声明字符串:

job_params = "[string(name: 'app_one', value: '4.8.6'), string(name: 'app_three ', value: '1.2.4'), string(name: 'app_ten', value: '2.7.1')]"

java.lang.ClassCastException: class org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep.setParameters() expects java.util.List<hudson.model.ParameterValue> but received class java.lang.String

ParametersAction使用列表

def List job_params = [ string(name: 'app_one', value: '4.8.6'), string(name: 'app_three ', value: '1.2.4'), string(name: 'app_ten', value: '2.7.1') ]

© www.soinside.com 2019 - 2024. All rights reserved.