use*_*760 11 groovy jenkins jenkins-pipeline
我有一个管道作业,它使用两个独立的节点(一个用于构建,一个用于测试),我想在我的两个代码块之间共享一个变量Jenkinsfile.我认为这是可能的,但我对groovy和Jenkinsfile概念很新.以下是目前的相关代码:
node('build') {
stage('Checkout') {
checkout scm
}
stage('Build') {
bat(script: 'build')
def rev = readFile('result')
}
}
node('test') {
stage('Test') {
def SDK_VERSION = "5.0.0001.${rev}"
bat "test.cmd ${env.BUILD_URL} ${SDK_VERSION}"
archiveArtifacts artifacts: 'artifacts/**/*.xml'
junit 'artifacts/**/*.xml'
}
}
Run Code Online (Sandbox Code Playgroud)
我想在构建阶段分配"rev"变量,但是然后将它连接到Test阶段的SDK_VERSION变量.我的错误是:
groovy.lang.MissingPropertyException: No such property: rev for class: groovy.lang.Binding
Run Code Online (Sandbox Code Playgroud)
mko*_*bit 11
只需在node块之前定义变量:
def rev = ''
node('build') {
stage('Checkout') {
checkout scm
}
stage('Build') {
bat(script: 'build')
rev = readFile('result')
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13835 次 |
| 最近记录: |