Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to inject Jenkins environmental variables into pom.xml

Egor Erofeev June 20, 2018

Hi,

I'm trying to get the version number of my plugin to be equal Jenkins BUILD_NUMBER environment variable.

Plugin is built inside docker container using command:

docker run --rm --volume $PWD/src/jira_plugin/:/opt/atlas/ codeclou/docker-atlassian-sdk:latest  atlas-package

POM.xml:

<project>

<version>${jenkins.buildNumber}</version>

...

   <properties>
        <jenkins.buildNumber>${env.BUILD_NUMBER}</jenkins.buildNumber>
    </properties>

</project>

Result:

[INFO] Building jar: /opt/atlas/target/test-null.jar
..[ERROR] Failed to execute goal
com.atlassian.maven.plugins:maven-jira-plugin:6.3.15:generate-obr-artifact
(default-generate-obr-artifact) on project test:
Source '/opt/atlas/target/test${env.BUILD_NUMBER}.jar' does not exist

Nevertheless command

 echo `printenv` 

in docker correctly displays BUILD_NUMBER.

Question:

What should I add in pom.xml to inject BUILD_NUMBER var in pom.xml  and to display version correctly?

Any help would be greatly appreciated.

1 answer

1 accepted

0 votes
Answer accepted
Egor Erofeev June 25, 2018

I figured it out:

docker run -e BUILD_NUMBER="${BUILD_NUMBER}" ...

So the variable will be injected and can be used in pom.xml.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events