Jenkins:无法在流水线阶段定义变量 [英] Jenkins: Cannot define variable in pipeline stage

查看:3230
本文介绍了Jenkins:无法在流水线阶段定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的脚本:

  pipeline {
agent none
stages {
stage(first){
def foo =foo //失败,并显示WorkflowScript:5:预计在第5行,第13列有一个步骤。
shecho $ {foo}
}
}
}

然而,我得到这个错误:

  org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败: 
WorkflowScript:5:预计会有一个步骤@第5行,第13列。
def foo =foo
^

我在Jenkins 2.7.4和Pipeline 2.4上。

解决方案

Jenkins Pipelines的声明模型有一个限制的语法子集,它允许在阶段块中查看更多信息的语法指南。您可以通过将步骤封装在脚本{...} 块中来绕过该限制,但是结果是,您将失去验证语法,参数等脚本块。


I'm trying to create a declarative Jenkins pipeline script but having issues with simple variable declaration.

Here is my script:

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

However, I get this error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: Expected a step @ line 5, column 13.
           def foo = "foo"
           ^

I'm on Jenkins 2.7.4 and Pipeline 2.4.

解决方案

The Declarative model for Jenkins Pipelines has a restricted subset of syntax that it allows in the stage blocks - see the syntax guide for more info. You can bypass that restriction by wrapping your steps in a script { ... } block, but as a result, you'll lose validation of syntax, parameters, etc within the script block.

这篇关于Jenkins:无法在流水线阶段定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆