我将Jenkinsfile
保留在存储库中为“精简”:
@Library('utils') _
def svcName = currentBuild.rawBuild.project.parent.displayName
def sharedLibrary = new pythonApps()
def buildCommands = [ compileData: "python compile.py" ]
timestamps {
commonPipeline(sharedLibrary, svcName, buildCommands)
}
commonPipeline.groovy
在vars/
下的共享库中。在这里(被截断):
#!/usr/bin/env groovy
def call(sharedLibrary, svcName, buildCommands) {
pipeline {
agent { ... }
stages {
stage('Compilation') {
steps {
script {
sharedLibrary.executeStage("compile", buildCommands['compileData'])
}
}
}
... other stages ...
}
}
}
我想允许具有多个目的的多个团队使用同一管道,但使用不同的sharedLibrary
。
当我需要某些作业来传递参数时,就会出现问题。
我尝试将参数部分添加到共享库的executeStage
内,但是按照如下方式:https://jenkins.io/doc/book/pipeline/syntax/#parameters参数只能位于pipeline
或stage
块内,其中{{ 1}}我在executeStage
街区。
有什么办法做到这一点?
答案 0 :(得分:0)
发现了能力。我可以在executeStage
中添加以下内容:
def executeStage(...) {
properties([
parameters([
booleanParam(defaultValue: false, name: 'test')
])
])
...
}
答案 1 :(得分:-1)
需要在管道开始运行之前定义参数。例如。参数中可以包含要在其上运行管道的标签,因此需要在选择代理之前而不是在分配代理之后对其进行定义。
请注意,具有“相同但不同”的构建指令的功能通常是通过具有相同共享库的不同管道实现的,反之亦然。保持Jenkinsfile极短的目标可能不在设计师的关注范围之内。这样,如果您绝对反对在Jenkinsfile中定义管道,则可以尝试在库的不同分支中使用参数。