如何在jenkinsfile的shell命令中使用pom版本? [英] How to use pom version in shell command in jenkinsfile?

查看:322
本文介绍了如何在jenkinsfile的shell命令中使用pom版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Jenkinsfile中获取pom.xml版本,然后在shell脚本中使用该版本. 尝试使用pom.version时,这会给出异常bad substitution.传递pom版本的正确语法是什么?

I am trying to get pom.xml version within Jenkinsfile and then use that version in a shell script. This gives the exception bad substitution when trying to use pom.version. What is the correct syntax to pass the pom version?

script {
    def pom = readMavenPom file: 'pom.xml'

    withCredentials(...) {

        sh '''#!/bin/bash                                        
              cp "${WORKSPACE}/target/stats-${pom.version}-shaded.jar" /xyz
        '''
    }                   
}

我为readMavenPom cmd安装了Pipeline Utility Steps插件,但没有重新启动Jenkins.是否需要重新启动Jenkins?

I installed Pipeline Utility Steps plugin for readMavenPom cmd but didn't restart Jenkins. Is it necessary to restart Jenkins?

推荐答案

如果要替换${pom.version},则需要使用GString.您使用的三引号定义了不支持变量替换的多行Java字符串.您需要将'''替换为""",以定义可以替换${WORKSPACE}${pom.version}变量的多行GString.

If you want to substitute ${pom.version}, you need to use GString. The triple-quote you used defines a multiline Java string that does not support variables substitution. You need to replace ''' with """ to define a multiline GString that can substitute both variables, ${WORKSPACE} and ${pom.version}.

这篇关于如何在jenkinsfile的shell命令中使用pom版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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