Lac*_*lev 1 groovy jenkins jenkins-pipeline
我们有一些类似的应用程序已通过脚本化管道进行部署,该管道基本上是所有应用程序的C&P。我想将整个管道移到Jenkins docs所暗示的Jenkins共享库中。
因此,假设我的代码中包含以下“管道” var/standardSpringPipeline.groovy:
#!groovy
def call() {
node {
echo "${env.BRANCH_NAME}"
}
}
Run Code Online (Sandbox Code Playgroud)
然后-Jenkins文件:
@Library('my-jenkins-lib@master') _
standardSpringPipeline
echo "Bye!"
Run Code Online (Sandbox Code Playgroud)
不幸的是,由于我不了解的原因,这无法正常工作。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
Run Code Online (Sandbox Code Playgroud)
有什么线索为什么这不起作用(请参见上面的输出),什么是正确的方法?
对于无参数方法,不能使用可选的括号。从Groovy文档(重点是我的):
如果有至少一个参数并且没有歧义,则方法调用可以省略括号:
Run Code Online (Sandbox Code Playgroud)println 'Hello World' def maximum = Math.max 5, 10对于没有参数或模棱两可的方法调用,必须使用括号:
Run Code Online (Sandbox Code Playgroud)println() println(Math.max(5, 10))
standardSpringPipeline由于如何编译,行为就像方法一样。如果添加echo "$standardSpringPipeline",则可以更清楚地知道它是可以调用的已编译类。
要解决您的问题,只需在通话中添加括号:
standardSpringPipeline()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82 次 |
| 最近记录: |