Reputation: 201
I was searching over the web for a solution to my problem and I almost tried everything I found but I still didn't get the right one.
Here is my problem shortly :
In my pom.xml file I have a user property in properties section like this :
<properties>
<carbon.appmgt.version>value-from-command-line</carbon.appmgt.version>
</properties>
This property is used in dependencies section like this :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.appmgt</groupId>
<artifactId>org.wso2.carbon.appmgt.impl</artifactId>
<version>${carbon.appmgt.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Its value must be read from the command line when launching the "Maven Perform Release" action via Jenkins.
In the job build section Goals and options are :
-Ddb.username=root -Ddb.password=paritelWso2 -Dip.adress=emm.sifast.fr -Ddb.connection=com.mysql.jdbc.Driver -Ddb.connection.wso2emmdb=jdbc:mysql://localhost:3306/WSO2DM_DB -Ddb.connection.wso2carbondb=jdbc:mysql://localhost:3306/WSO2CARBON_DB -Ddb.connection.wso2amdb=jdbc:mysql://localhost:3306/WSO2AM_DB?autoReconnect=true&relaxAutoCommit=true clean install
Is there any solution to pass the current release version via maven commands ?
Upvotes: 2
Views: 8420
Reputation: 534
For someone trying to pass variable from Jenkins pipeline to local pom.xml file., what you can do is pass the argument through mvn clean install console command.
What I did here is, I passed a boolean build parameter value SKIP_JUNIT_TEST that can control the value passed through arguments.
You can pass the argument like this:
sh 'mvn clean install -Dmaven.test.skip=${SKIP_JUNIT_TEST}'
here maven.test.skip is the variable I have set in pom.xml
Upvotes: 1
Reputation: 201
the problem was related to a small detail for which we didn't pay much attention : I must use :
-Dargeuments='-Dcarbon.appmgt.version=X.Y.Z'
instead of :
-Dargeuments="-Dcarbon.appmgt.version=X.Y.Z"
Upvotes: 1
Reputation: 10382
First, to specify some system properties with Jenkins and the Maven release plugin, you have to use the -Darguments property.
As Maven forks the process to do the release, Maven is not using the information from the build section.
In the Maven release section, you have to set something like that:
(please also add all the relevant properties like db.username, ...)
Jenkins will affect the value 1.2.3 to the Maven system property carbon.appmgt.version.
Next, you just have to remove your property section in your Maven pom.xml file (as Jenkins will directly set the value for carbon.appmgt.version).
It should do the job :)
Upvotes: 0