我有一个用例,其中我有多个管道,但每个管道在每个阶段运行相同的代码,唯一的区别是有些将运行所有阶段,有些将运行很少的阶段。
如果我创建单独的 Jenkinsfile 具有相同的阶段代码,并且如果有一天我更改配置,我将不得不在所有地方进行更改。
那么是否可以在单独的文件中创建
stage
作为共享库,然后将它们导入到特定于管道的 Jenkinsfile 中?stage('A') {
steps {
//something
}
}
B.groovy
stage('B') {
steps {
//something
}
}
C.groovy
stage('C') {
steps {
//something
}
}
所以在 Pipeline-1 Jenkinsfile 中我可以使用:
pipeline {
agent any
stages {
import A
A.call()
import B
B.call()
import C
C.call()
}
}
等等。 我知道上面的语法不正确,它只是为了解释需要做什么。