Sumit Sarkar
Sumit Sarkar

Reputation: 49

How i can get the pom version in jenkins pipeline job

I want to get the pom version in one of my stage.For this i have this pipeline script. I have Pipeline Utility Steps plugin installed.

stage ('Publish Stage') {
            steps {
                 pom = readMavenPom file: 'pom.xml'
                 echo pom.version
            }
        }

I am getting error with this, can anybody tell what mistake am i doing?

Upvotes: 0

Views: 7079

Answers (2)

Vishal
Vishal

Reputation: 2173

Writing steps{} block and wrapping it inside script{} would work but in my case, I just used the variable through the environment.

   stage('Read Pom Version'){
       pom = readMavenPom file: 'pom.xml'
       env.POM_VERSION = pom.version

       sh '''#!/bin/bash -xe
           echo $POM_VERSION
       '''.stripIndent()
    }

Let say the version inside my pom is 1.0.0. Above jenkins stage prints following:

    1.0.0
    echo 1.0.0

Upvotes: 2

Rob Hales
Rob Hales

Reputation: 5319

You cannot assign to a groovy variable in a declarative pipeline like that. You can only run steps in the steps{} block. If you wrap this in a script{} block, it will work. Take care not to declare the variable locally if you need it available elsewhere.

Upvotes: 4

Related Questions