How can I change 'MAJOR' AND 'MINOR' with gitflow-maven-plugin - maven

I'm currently learning Maven and I've been doing some testing with gitflow-maven-plugin, I have set up and get it work, now it can change the last digit of the versioning (so if the release version for master branch is 1.0.0, develop version is 1.0.1-SNAPSHOT), I tried to control the change of the digit by using :
mvn -B gitflow:release -DversionDigitIncrement=1
I tried to set DversionDigitIncrement to 0, 1, 2 but the only number changed is the last digit (which is the 'PATCH'), how can I test if the other two numbers change properly? Which commands I should ues or do I need to change configuration in POM file?
Been messing around for a whole day now. Many thanks. (I wanted it to follow semantic versioning naming rule)

try to use it after a release-start :
mvn -B gitflow:release-start
mvn -B gitflow:release-finish -DversionDigitToIncrement=0
mvn -B gitflow:release -DversionDigitToIncrement=0
OR if you want to change develop version at release-start :
mvn -B gitflow:release-start -DcommitDevelopmentVersionAtStart=true -DversionDigitToIncrement=0
In your case, 0 to major and 1 to minor
https://github.com/aleksandr-m/gitflow-maven-plugin#additional-goal-parameters

Related

How to pin revision number of Jenkins build?

I have a Jenkins multiphase job that
gets an update from version control (Subversion)
does a Maven build. Couldn't be more cut and dry.
The 1. above, svn update, does return a latest revision number. I would like to fetch that into 2. so that the build and its associated artifacts do have that number pinned to them, if any way possible in the artifact name itself but, if not, in the build history. Is there a way to do it and how (e.g. using the subversion or another plugin)?
I am using the buildnumber plugin to fetch the build number and generate a small text file that is contained inside my WAR artifacts, which makes it subsequently available via HTTP. But to see it, one must either first deploy the artifact or at least extract its contents. I would like it more readily visible in Jenkins.
You should take a look at How to get SVN revision number in Jenkins Workflow Plugin? - He solved the problem with:
def revision = 'svn info'.execute().in.text.split('\n').find { it.startsWith('Revision') }.split(':')[1].trim()
He's obviously using the latest Jenkins version, but if you're using one of the old Jenkins versions you can simply run the following command and parse the result to get the revision number you want:
svn info -r HEAD
BTW you can use a Jenkins constant too. In the browser you can open http://your-jenkins-host/env-vars.html/ and you will find a constant named SVN_REVISION. Each job build keep the SVN revision into that variable.

Is there a way to set the Maven version number dynamically?

I would like to use Maven to produce an artifact in zip format. To give you some background; my project includes an APS package (Application Packaging Standard, used to provision cloud applications on the Parallels platform). This package is a zip file that contains a combination of XML as well as PHP files. It is generated by an APS plugin from within Eclipse and its name always includes the version and release number of its contents.
What I am trying to do is generate a zip file with Maven that would be kind of a release candidate that will be eventually sent to customers and would include not only the actual APS package but also other files such as README, User Guide.pdf, etc;. I would like the name of this zip file to contain the version number of the version number of the APS package. Currently I can generate this manually by using something like "mvn -Dversion=1.2.3-4 package" but I would like to automate the process and ideally run this from Jenkins.
Basically, my strategy is to run a script that would extract the version number from the initial APS package, once that is done, my script can invoke Maven and can pass this parameter to it so it can generate the final zip with the proper version number. This is fine but again, I need to run this script manually and I am looking for an automated process.
My question is; is it possible to invoke this script from within Maven and use its return as a parameter to set the version name (or the name of the file that will be generated) at run time? As I mentioned, I would like eventually Jenkins to handle this. It can pick up the pom file but I am not sure how it could kind of "auto configure" itself to have the proper version number.
Thanks is advance.
From jenkins build you can use profile with ${BUILD_NUMBER}:
<profile>
<id>jenkins</id>
<build>
<finalName>${artifactId}-${version}-${BUILD_NUMBER}</finalName>
</build>
</profile>
Then run in jenkins:
clean install -Pjenkins
I use the SVN (or any source versioning system) version to identify the software builds.
By simply executing this
REVISION=`svn info | grep '^Revision:' | sed -e 's/^Revision: //'`
on the sourcers folder you get the right value in $REVISION, then you can use it for your maven build
mvn -Dversion=1.2.3-$REVISION package
easy and clean

mvn release:prepare doesn't work using maven 3

My JAVA_HOME is properly set up to /usr/local/java/jdk1.7.0_01
$echo $JAVA_HOME
/usr/local/java/jdk1.7.0_01
$sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
* 2 /usr/local/java/jdk1.7.0_01/bin/java 1 manual mode
3 /usr/local/java/jre1.7.0_01/bin/java 1 manual mode
I am using mvn release:prepare plugin to produce the git tag and flip project's version in the pom.xml. It works perfect if I use maven 2.2.1 When I use maven 3.0.4, I get:
[INFO] Error: JAVA_HOME is not defined correctly.
[INFO] We cannot execute /usr/local/java/jdk1.7.0_01/bin/java/bin/java
I guess there might be a bug in maven 3, when it runs, it tries to append /bin/java twice to my JAVA_HOME.
Try using the standard Oracle/Sun JDK, if that is an option at all. I have hit this myself before on Debian/Ubuntu. I never had the patience to figure out what was wrong with the OpenJDK, but it doesn't cope well with Maven. Or... at least... such was my observation.
JAVA_HOME must point to jre, then set :
export JAVA_HOME=/usr/local/java/jdk1.7.0_01/jre
Search JAVA_HOME in your mvn command file (use which mvn to find it).
Mine does handle the JAVA_HOME if not already defined.
So perhaps you can get around it by unset JAVA_HOME
remove the file in old maven home and it will change to new one.
mv /usr/local/Cellar/maven/3.8.1/libexec /usr/local/Cellar/maven_bak
before that, you need to export your jdk and maven firstly. and how to do this, you can see following link.
https://stackoverflow.com/a/67715235/11679986

Which Maven goal to use as no-op (for scripting purposes)?

I have a script on Jenkins CI which optionally does dependency:go-offline. The other option should be to do nothing. But I can't put "" in there - it must be a goal.
So - which one would you pick? It should:
Be in central, always reachable
Take minimum time
Have minimal output
Have no side effects
I was thinking of some help:... goal but those tend to have a lot of output. Any better?
You can use this goal and option:
mvn --quiet help:help
the -q,--quiet option causes the output to only show errors.
Note that Jenkins allows you to add options like --quiet as diplayed in the usage: mvn [options] [<goal(s)>]. You configure these in the Jenkins job’s “Goals and options” field.
Check mvn --help output for further information.
I know this is an old question, but I came across it when I had the same requirement and it's still unanswered, so I'm posting for anyone who needs it in future.
This still depends on the current project, but could be useful if you don't want to hardcode a specific plugin for some reason:
mvn -pl ./ validate
-pl ./ means only current project, ignore submodules. Alternatively you could specify specific project by relative path or [groupId]:artifactId.
validate is the first phase of the Default Lifecycle. Doesn't change or build anything.
Alternatively, if you don't have a maven project at all, some maven plugins, or rather specific plugin goals, can be executed without it. E.g.:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:help
It would still scan projects if it sees a POM in the current directory. And of course you still need to have the plugin in your local repository.

Jenkins multi-configuration project user-defined axis environment variable

I am trying to set up a multi-configuration project in Jenkins with a single user-defined axis (call it "axis"). The value associated with each configuration would then be used to invoke top-level maven targets in ${axis}/pom.xml. The trouble is, I can't find the proper syntax for this, if indeed it does exist (${axis}, $axis, $AXIS, and ${env.axis} all fail). I would think it would be shell syntax, which it doesn't seem to be, but regardless it should be either simple or impossible. Is it possible?
Is your Jenkins installation running on Windows?
For each Custom Axis, an environment variable is created. You can refer to your custom axis using ${axis} if your server is running Linux, but on Windows you must refer to it as %axis%
${axis}/pom.xml should work in my experience.
I appreciate that OP has solved this in a different way, but for the record the following works in Hudson in Windows and Linux. I haven't tried it in Jenkins:
The syntax you need for this is simply $axis/pom.xml
I defined an axis of BuildProfile=compile unitTest integrationTest
And in the Maven 3 configuration (under Advanced properties) a POM file of $BuildProfile/pom.xml
The resulting builds gave the following output in the console (edited for brevity):
[1.7.0_25] $ C:\Users...\bin\mvn.bat clean install -V -B
-DBuildProfile=compile -f compile/pom.xml
[1.7.0_25] $ C:\Users...\bin\mvn.bat clean install -V -B
-DBuildProfile=unitTest -f unitTest/pom.xml
[1.7.0_25] $ C:\Users...\bin\mvn.bat clean install -V -B
-DBuildProfile=integrationTests -f integrationTests/pom.xml
We use a jdk axis and just use the name of the jdk so I think you could just use axis/pom.xml

Resources