我想将有关定义的所有内容移动到一个单独的 groovy 文件中并将其加载到管道中。我尝试过不同的事情。 函数被调用,但stages_to_run(并行的生成阶段)未启动。仅打印“Hello from function”) 好吧,我对groove还不够了解。但我知道我错误地调用了 stage_to_run 或 function()
文件:functions.groovy
def function() {
println 'Hello from function'
def map = [
...
]
def stages_to_run = map.collectEntries { key, value ->
[
...
]
}
stages_to_run
}
return this
文件:pipeline.jenkins
def commonfunctions
pipeline {
agent any
stages {
stage('Compare:') {
steps {
script {
commonfunctions = load 'pipelines/functions.groovy'
commonfunctions.function()
...
......................
你的函数所做的就是返回
<String, Closure>
的地图。管道中没有任何东西可以执行它。尝试实际运行这些闭包,而不是生成它们的映射。
def function() {
println 'Hello from function'
def map = [
...
]
map.each { key, value ->
stage(key) {
...
}
}
}
return this