相关疑难解决方法(0)

在Groovy中'vs'"vs'''.何时使用什么?

我在Groovy中变得非常困惑.何时使用StringsGroovy中的内容?

1)单行情 - ' '
2)双行情 - " "
3)三行情 -'''

我的代码:

 println("Tilak Rox")
 println('Tilak Rox')
 println('''Tilak Rox''')
Run Code Online (Sandbox Code Playgroud)

所有都倾向于产生相同的结果. 什么时候用?

groovy operators

12
推荐指数
2
解决办法
1872
查看次数

Jenkins 管道 - 如何在不首先调用 node() 的情况下加载 Jenkinsfile?

我有一个有点独特的设置,我需要能够动态加载位于我正在构建的 src 之外的 Jenkinsfiles。Jenkinsfiles 本身通常调用node(),然后调用一些构建步骤。这会导致多个执行器不必要地被消耗,因为我需要已经调用了 node() 才能使用加载步骤来运行 Jenkinsfile,或者如果我将 Jenkinsfile 作为字符串读取并执行它,则执行 groovy。

我今天的工作用户界面中有什么:

@Library(value='myGlobalLib@head', changelog=fase) _

node{
    load "${JENKINSFILES_ROOT}/${PROJECT_NAME}/Jenkinsfile"
}
Run Code Online (Sandbox Code Playgroud)

加载的 Jenkinsfile 通常也会调用 node()。例如:

node('agent-type-foo'){
    someBuildFlavor{
        buildProperty = "some value unique to this build"
        someConfig = ["VALUE1", "VALUE2", "VALUE3"]
        runTestTarget = true
    }
}
Run Code Online (Sandbox Code Playgroud)

这会导致管道运行期间消耗 2 个执行程序。理想情况下,我加载 Jenkinsfiles 时无需先调用 node(),但每当我尝试时,我都会收到一条错误消息,指出:

"Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node"
Run Code Online (Sandbox Code Playgroud)

有没有办法在没有 hudson.FilePath 上下文的情况下加载 Jenkinsfile 或执行 groovy?我似乎在文档中找不到任何内容。我现在要预处理 Jenkinsfiles 以删除它们对 node() …

jenkins jenkins-pipeline

5
推荐指数
1
解决办法
9823
查看次数

标签 统计

groovy ×1

jenkins ×1

jenkins-pipeline ×1

operators ×1