如何使用管道代码

时间:2017-11-27 07:34:11

标签: jenkins groovy jenkins-pipeline

我正在尝试将自由样式作业转换为管道作为代码。我有大量以下需要在从属节点上运行的groovy命令。

**stage ('Execute Groovy')**
def project = new XmlParser().parse( "target/checkout/pom.xml" )
def artifactID = project.artifactId.text()
def projectVersion = project.version.text()
def tag = "$artifactID-$projectVersion"
new File('release_info').text = "RELEASE_TAG=$tag\nRELEASE_VERSION=$projectVersion"

错误:

  

“java.io.FileNotFoundException:/target/checkout/pom.xml(没有这样的文件   或目录)在java.io.FileInputStream.open0(本机方法)“

我从输出中看到,groovy正在master上执行(我知道这是groovy的本质)并且无法找出文件路径并抛出错误。

如何使用管道

在从属节点上执行groovy命令

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用管道实用程序步骤(https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readmavenpom-code-read-a-maven-project-file)中的readMavenPom步骤。