groovy 如何将参数从Jenkins PipelineJob传递到bash脚本?

scyqe7ek  于 5个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(48)

我有一个Jenkins的工作流管道,它调用了一个groovy脚本。
然后我的groovy脚本运行许多作业,每个作业都调用一个bash脚本来执行实际的测试。
我希望能够在运行时从jenkins UI(构建w/ parameters时)在管道中设置一个变量,并使该参数可以从我的bash脚本访问。
这是否可能使用工作流管道?

dgenwo3n

dgenwo3n1#

无插件

  • 使用参数调用子作业[...]
  • 在子作业中接收参数并将其作为环境变量注入
  • 在bash脚本中将其作为环境变量读取
    上级职务
pipeline {
    agent any
    stages {
        stage('parent_job') {
            steps {
                script {
                    env.GLOBAL_VARIABLE = "foo"
                    build job: "call_child_bash", wait: true, parameters: [string(name: 'parent_variable', value: "foo")]
                }                
            }
        }
    }
}

字符串

儿童工作

pipeline {
    agent any
    stages {
        stage('child_bash') {
            steps {
                script {
                    env.GLOBAL_VARIABLE = params.parent_variable
                    sh "/tmp/sandbox/child_bash.sh"
                }
            }
        }
    }
}


x1c 0d1x的数据

子bash:/tmp/sandbox/child_bash.sh

echo "the global GLOBAL_VARIABLE value is $GLOBAL_VARIABLE"

父作业结果


下级作业结果


相关问题