gpt4 book ai didi

Jenkins :无法在管道阶段定义变量

转载 作者:行者123 更新时间:2023-12-04 14:00:57 26 4
gpt4 key购买 nike

我正在尝试创建一个声明性 Jenkins 管道脚本,但在简单变量声明方面存在问题。

这是我的脚本:

pipeline {
agent none
stages {
stage("first") {
def foo = "foo" // fails with "WorkflowScript: 5: Expected a step @ line 5, column 13."
sh "echo ${foo}"
}
}
}

但是,我收到此错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: Expected a step @ line 5, column 13.
def foo = "foo"
^

我在 Jenkins 2.7.4 和 Pipeline 2.4 上。

最佳答案

Jenkins Pipelines 的声明式模型具有在 stage 中允许的受限语法子集。块 - see the syntax guide for more info .您可以通过将步骤包装在 script { ... } 中来绕过该限制。阻止,但结果是,您将失去对 script 中的语法、参数等的验证。堵塞。

关于 Jenkins :无法在管道阶段定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45236824/

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