我遇到一种情况,必须将一个作业的内部版本号传递给另一个作业,而下一个作业将使用该编号作为参数。
stages {
stage('Build Job1') {
steps {
script {
build job: "001_job"
$build_001= env.BUILD_NUMBER of 001_job
echo env.BUILD_NUMBER //this echos the build number of this job and not 001_job
}
}
}
stage('job_002') {
steps {
script {
build job: "job_002", parameters: [string(name: "${PAYLOAD_PARAM}", value: "$build_001")]
}
}
}
}
}
答案 0 :(得分:0)
我想出了一种方法。 需要具有全局环境变量,然后通过功能分配内部版本号,如以下解决方案中所示:
pipeline {
environment {
BUILD_NUM = ''
}
agent {
label 'master'
}
stages {
stage('Build Job1') {
steps {
script {
def build job: "001_job"
def build_num1 = build_job.getNumber()
BUILD_NUM = "${build_num1}"
echo BUILD_NUM //build number of oo1/job
}
}
}
stage('job_002') {
steps {
script {
build job: "job_002", parameters: [string(name: "${PAYLOAD_PARAM}", value: BUILD_NUM))]
}
}
}
}
}