1

I am trying to find out if I could get the value of a variable declared inside a Java program or maven-plugin and store it in a Jenkins environment variable.

This is because the Jenkins file has to create a new git branch from dev and call it Release-9.0.86 for example but the version number is inside a pom.xml.

I have already written a maven-plugin that retrieves the version from the pom.xml an writes it into another XML file, but I need to know if I could send the version to Jenkins to handle it.

M-Razavi
  • 3,327
  • 2
  • 34
  • 46
zarzanduil
  • 70
  • 6
  • Possible duplicate of [Getting Project Version from Maven POM in Jenkins](https://stackoverflow.com/questions/9893503/getting-project-version-from-maven-pom-in-jenkins) – M-Razavi May 28 '19 at 11:32

1 Answers1

2

You could perhaps create a properties file instead of a xml file with the needed information. Example contents of created branch-name.properties file:

NEW_BRANCH_NAME=Release-9.0.86

Then you can add a build step "Inject environment variables" after the one that produces the properties file, and configure that to read the properties file you just created.

Properties File Path: branch-name.properties

After that you can use the environment variables as usual in the jenkins build, for example a "Execute shell" build step that creates the branch:

git branch ${NEW_BRANCH_NAME}

To then push the newly created branch you could add a "Git Publisher" post-build action.

Branch to push: ${NEW_BRANCH_NAME}

Please note that it might be useful to configure Git Publisher to "Push Only If Build Succeeds" i.e. branch will not be created if the build fails for any reason.

Jonas Berlin
  • 3,344
  • 1
  • 27
  • 33