user1298426
user1298426

Reputation: 3717

How to use pom version in shell command in jenkinsfile?

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?

Upvotes: 1

Views: 347

Answers (1)

Szymon Stepniak
Szymon Stepniak

Reputation: 42262

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

Upvotes: 1

Related Questions