如何使用变量名作为声明性Jenkins的参数运行ArtifactoryMavenBuild?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用变量名作为声明性Jenkins的参数运行ArtifactoryMavenBuild?相关的知识,希望对你有一定的参考价值。
我正在尝试使用声明性语法编写Jenkins管道(如果我真的无法取得任何进展,我将切换到脚本)。但是,我无法弄清楚如何获取要存储到变量的函数的返回值,因此我可以将该变量用作下一个函数的参数。
我的管道阶段看起来像这样:
stage ('Build') {
steps {
def artServer = getArtifactoryServer(artifactoryServerID: 'my-server')
def mvBuild = newMavenBuild()
def buildInfo = newBuildInfo()
ArtifactoryMavenBuild(mavenBuild: mvBuild, tool: "M3", pom: "pom.xml", goals: "-B clean test -Dmaven.test.failure.ignore", opts: "", buildInfo: buildInfo)
}
}
我的错误日志是:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 19: Expected a step @ line 19, column 17.
def artServer = getArtifactoryServer(artifactoryServerID: 'GE-Propel-Artifactory')
^
WorkflowScript: 20: Expected a step @ line 20, column 17.
def mvBuild = newMavenBuild()
^
WorkflowScript: 21: Expected a step @ line 21, column 17.
def buildInfo = newBuildInfo()
ArtifactoryMavenBuild函数在我这样设置时起作用:
ArtifactoryMavenBuild(mavenBuild:newMavenBuild(),工具:“M3”,pom:“pom.xml”,目标:“ - B clean test -Dmaven.test.failure.ignore”,opts:“”,buildInfo:newBuildInfo())
但我需要能够再次引用mvBuild和buildInfo以用于后续步骤。
Artifactory插件的声明性jenkins文档在这里:https://jenkins.io/doc/pipeline/steps/artifactory/
答案
尝试将脚本代码包装成script {}
步骤,如下所示:
stage ('Build') {
steps {
script {
def artServer = getArtifactoryServer(artifactoryServerID: 'my-server')
def mvBuild = newMavenBuild()
def buildInfo = newBuildInfo()
ArtifactoryMavenBuild(mavenBuild: mvBuild, tool: "M3", pom: "pom.xml", goals: "-B clean test -Dmaven.test.failure.ignore", opts: "", buildInfo: buildInfo)
}
}
}
以上是关于如何使用变量名作为声明性Jenkins的参数运行ArtifactoryMavenBuild?的主要内容,如果未能解决你的问题,请参考以下文章