gpt4 book ai didi

Jenkins - 将脚本化管道导出到共享库中

转载 作者:行者123 更新时间:2023-12-02 21:12:01 25 4
gpt4 key购买 nike

我们有一些类似的应用程序,它们是通过脚本化管道部署的,该管道基本上是所有应用程序的 C&P。我想将整个管道移至 Jenkins 共享库中,如 Jenkins docs 中所示。 .

因此,假设我在 var/standardSpringPipeline.groovy 中有以下“管道”:

#!groovy

def call() {

node {
echo "${env.BRANCH_NAME}"
}
}

然后 - Jenkins 文件:

@Library('my-jenkins-lib@master') _

standardSpringPipeline

echo "Bye!"

不幸的是,由于我不明白的原因,这不起作用。 Jenkins 输出类似:

> git fetch --no-tags --progress ssh://git@***.com:7999/log/my-jenkins-lib.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision 28900d4ed5bcece9451655f6f1b9a41a76256629 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 28900d4ed5bcece9451655f6f1b9a41a76256629
Commit message: "NOJIRA: ...."
> git rev-list --no-walk 28900d4ed5bcece9451655f6f1b9a41a76256629 # timeout=10
[Pipeline] echo
Bye!
[Pipeline] End of Pipeline

知道为什么这不起作用(请参阅上面的输出)以及正确的方法是什么?

最佳答案

对于无参数方法,不能使用可选括号。来自 Groovy documentation (强调我的):

Method calls can omit the parentheses if there is at least one parameter and there is no ambiguity:

println 'Hello World'
def maximum = Math.max 5, 10

Parentheses are required for method calls without parameters or ambiguous method calls:

println() 
println(Math.max(5, 10))

由于编译方式,standardSpringPipeline 的行为类似于方法。如果添加 echo "$standardSpringPipeline" ,就更清楚它是一个可以调用的编译类。

要解决您的问题,只需在调用中添加括号即可:

standardSpringPipeline() 

关于Jenkins - 将脚本化管道导出到共享库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49613169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com