【发布时间】:2019-01-10 18:05:00
【问题描述】:
我想将steps 和post 包装在一个函数中。
这很好用:
pipeline {
agent any
stages {
stage('Test') {
steps {
whateverFunction()
}
post {
sh 'echo test'
}
}
}
}
void whateverFunction() {
sh 'ls /'
}
但是一旦我打包步骤并在我的函数中发布它就不起作用。 (失败的错误是:steps in a stage must be in a ‘steps’ block.)
pipeline {
agent any
stages {
stage('Test') {
whateverFunction()
}
}
}
void whateverFunction() {
steps {
sh 'echo test'
}
post {
sh 'echo test'
}
}
我还尝试使用steps,然后在该步骤中调用我的函数,其中包含steps。基本上在steps 中扭曲steps,这会导致不执行任何步骤的行为。 (但显然这将是一个有效的 Jenkins 文件)
是否可以在一个阶段内拥有一个包含steps 和post 的函数。或者有没有办法实现类似的功能?
【问题讨论】:
标签: jenkins groovy jenkins-declarative-pipeline