How to use pom version in shell command in jenkinsfile?

∥☆過路亽.° 提交于 2021-01-28 20:53:45

问题


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
        '''
    }                   
}

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


回答1:


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}.



来源:https://stackoverflow.com/questions/60971483/how-to-use-pom-version-in-shell-command-in-jenkinsfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!