我正在尝试运行一个简单的管道作业,该作业会触发另一个管道作业并发送参数值。我在下面的示例中尝试了一个简化的用例]
Piepeline-父母
pipeline{
agent any
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')
}
stages {
stage('Invoke simple_child') {
steps {
input id: 'Environment', message: 'Approval', parameters: [choice(choices: ['FRST', 'QA', 'PROD'], description: '', name: 'depServer')], submitter: 'FCMIS-SFTP-LBAAS', submitterParameter: 'user'
build job: 'simple_child',
parameters: [string(name: 'CommitID', value: 'aa21a592d1039cbce043e5cefea421efeb5446a5'),string(name: 'Environment', value: "${depServer}"), string(name: 'Branch', value: "master")],
quietPeriod: 1
}
}
}
}
管道-孩子
pipeline{
agent none
parameters {
string(name: 'CommitID',
defaultValue: 'e2b6cdf1e8018560b3ba51cbf253de4f33647b5a',
description: 'This is to take the commitID for checkout')
string defaultValue: 'FRST', description: 'Environment to which the package needs to be deployed', name: 'depServer', trim: true
string defaultValue: 'master', description: 'Branch from which the commit needs to be pulled', name: 'Branch', trim: true
}
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')
}
stages {
stage('CodePull') {
agent {
label 'Linux'
}
steps {
echo "Testing"
echo "${params.depServer}"
}
}
}
}
当我运行父管道时,它不会触发子管道,但会给出如下错误
Started by user ARAV
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/sample_parent
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Invoke sample_pipleline)
[Pipeline] input
Input requested
Approved by ARAV
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: depServer for class: groovy.lang.Binding
[请帮助我了解我在这里做错了什么。感谢您的帮助!
groovy.lang.MissingPropertyException:无此类属性:depServer用于类:groovy.lang.Binding
这意味着您尚未定义变量depServer
。
通过将input
步骤的结果分配给变量depServer
来解决:
steps {
script {
def depServer = input id: 'Environment', message: 'Approval', parameters: [choice(choices: ['FRST', 'QA', 'PROD'], description: '', name: 'depServer')], submitter: 'FCMIS-SFTP-LBAAS', submitterParameter: 'user'
build job: 'simple_child',
parameters: [string(name: 'CommitID', value: 'aa21a592d1039cbce043e5cefea421efeb5446a5'),string(name: 'Environment', value: depServer), string(name: 'Branch', value: "master")],
quietPeriod: 1
}
}
我添加了一个script
块,以便能够创建和分配变量。
此外,depServer
参数中不需要为build
进行字符串插值,因此已将其删除。