title: How to update the POM version from Jenkins pipeline after build if tests are successful
body: <p>I inherited 2 projects, one depending on the other, both Maven projects building with Jenkinsfile.</p>
  <p>Project B has dependencies on some modules of project A.</p>
  <p>Right now the version in the pom.xml of project A is hardcoded, as is the version of the dependency in project B. Versions are managed in the Jenkinsfile, but not updated in the pom.xml. This sometimes causes problems with local builds for project B.</p>
  <p>I would like the versions in the poms of the modules of project A to be increased to reflect the builds, instead of being hardcoded.</p>
  <p>The suggestions I found online seemed old, and I am not sure they are relevant anymore. I am looking to use the best possible approach.</p>
  <p>Jenkinsfile:</p>
  <pre><code>env.VERSION = &quot;${env.BUILD_ID}-${(env.BRANCH_NAME).replace('/', '-')}&quot;
  if (env.BRANCH_NAME == &quot;master&quot;) {
      env.VERSION = env.BUILD_ID
  }
  
      stage ('Checkout') {
          checkout scm
          gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
  
          sh &quot;git config user.email email@email.email&quot;
          sh &quot;git config user.name 'jenkins-username'&quot;
          sh &quot;git tag -a -f -m 'Jenkins CI Build: ${env.BRANCH_NAME} ${env.BUILD_NUMBER}' ${version}&quot;
      }
      
      stage ('Build') {
          withCredentials(......) {
              ansiColor('xterm') {
                  sh &quot;docker build --build-arg VERSION=${env.VERSION}  --target build -t sometag:build .&quot;
                  docker_images.each{ image -&gt;
                      sh &quot;docker build --build-arg VERSION=${env.VERSION} --target ${image} -t ${rootRepo}/${image}:${env.VERSION} -t ${rootRepo}/${image}:${gitCommit} .&quot;
                  }
              }
          }
      }
  
  </code></pre>
  <p>pom.xml:</p>
  <pre><code>    &lt;groupId&gt;my.group&lt;/groupId&gt;
      &lt;artifactId&gt;my-artifact&lt;/artifactId&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
      &lt;version&gt;1234&lt;/version&gt;
  </code></pre>
  <p>Thanks.</p>