0

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?

Sumit Sarkar
  • 49
  • 3
  • 7

2 Answers2

4

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.

Rob Hales
  • 5,123
  • 1
  • 21
  • 33
2

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
Vishal
  • 1,963
  • 2
  • 20
  • 23