Maven-Release with Jenkins: Skip second test run - maven

We use Jenkins (2.150.1) together with M2 Release Plugin (0.14.0). After checkout from git we specified "Maven release build -> Release goals and options"
-Dresume=false release:prepare release:perform -DautoVersionSubmodules -Dgoals=deploy
and in the Build step we configured the maven "Goals and Options"
clean verify -U
When we start to perform a Maven release, I get asked e.g. a Release Version 1.0 and a new Version 1.1-SNAPSHOT.
Generally, everything works fine like the following way:
git clone
mvn changes versions to 1.0
mvn clean verify -U
mvn release perform
mvn changes version to 1.1-SNAPSHOT
mvn clean verify -U
mvn release perform
Question: Do you know how I can skip the second part? So maven does update to Version 1.1-SNAPSHOT but does NOT perform the following two steps?

Related

What is the supported way to change version on deploy for Artifactory Maven Jenkins plugin

I'm using the Maven jfrog plugin: https://jenkins.io/doc/pipeline/steps/artifactory/#rtmavendeployer-set-maven-deployer
I want to change the version of the artifact on deploy so it has the feature branch name in it.
I tried to run the set version goal. It succeeds but just totally ignores the version
rtMavenRun (
pom: "pom.xml",
goals: 'versions:set -DnewVersion=1.2.3-SNAPSHOT clean install',
resolverId: 'resolver-unique-id',
deployerId: 'deployer-unique-id'
)
The problem is the following: You call the goal versions:set and the phases clean and install in one Maven run. Before the first goal runs, Maven has already resolved the version for all goals/phases that are run. Therefore, you change the version in the POM, but as Maven has already read it, you will not be able to see it during this run.
What are possible solutions?
You can run versions:set first and then clean install in a separate Maven run.
You can use the property ${revision} in the definition of <version> and then set this property on the command line.

Jenkins artifactory release management plugin with mvn versions:use-releases

"mvn versions:use-releases (mvn goals)" remove the "SNAPSHOT" word on your dependencies, ONLY / DURING the specific build you've triggered, not modifying or parsing your pom.xml on the repo itself (like gitlab) this could be very helpful when using artifactory release management plugin because this process doesn't allow projects with SNAPSHOT word on pom.xml, however I have tried using the mvn versions:use-releases when doing a release on artifactory release plugin, but the build is failing due to the build read 1st the pom.xml (with snapshot) before executing the mvn goals that will remove the snapshot word, even I tried to put the mvn goals on the alternative maven goals and options under "enable artifactory release management"
is there any way to solve this?

Jenkins + Maven - How to execute shell script before release:perform cleans the project

I have a Maven project that generates a zip file with maven-assembly-plugin on mvn package
MyProy
|--pom
|--src/...
|--target
|---MyProy-something-1.0.0-SNAPSHOT-zip (contains /1.0.0-SNAPSHOT/...)
I created a Jenkins job and configured a shell script execution as a post step. This script copies the zip to a folder (/something) and unzips it
|-/something
|---1.0.0-SNAPSHOT
|---...
This works fine for builds. However I want to do the same when I launch a release. I installed Jenkins release plugin and in "configure release build" I added this tasks:
Before release build -> Maven task mvn release:prepare
After successful release build -> Maven task mvn release:perform
After successful release build -> Execute shell script - Copy zip and unzip.
I see the mvn release:perform execute correctly, for instance with version 1.0.0 but the problem is that when the script (3.) is launched it applies to the next development version (1.0.1-SNAPSHOT) instead of the release version (1.0.0).
This is how I managed to work around the problem:
Before release build
mvn release:prepare
After successful release build
mvn release:perform
mvc scm:checkout -DscmVersion=${releaseVersion} -DscmVersionType=tag
-f ${WORKSPACE}/target/checkout clean install
Execute shell script with copy and unzip
To sum up, after the release:perform I checkout the brand new tag, execute a clean install in the location of the downloaded tag and finally I execute the script that copies the zip and unzipes it.

Jenkins & Github, how to append a version number?

We have 2 branches in github,
master
release
In our jenkins we have a job for each of these branches.
We want to increment a version number programmatically for release each time jenkins builds the release. We want also to increment the version number in the github release branch. Can you give me some directions on how to do it and what jenkin plugins i need? Thanks
This can be performed using a simple command:
mvn release:prepare release:perform --batch-mode
Explanation:
release:prepare
Prepare for a release in SCM. Steps through several phases to ensure the POM is ready to be released and then prepares SCM to eventually contain a tagged version of the release and a record in the local copy of the parameters used. It will update your version number from e.g. "1.0.1-SNAPSHOT" to "1.0.1" and commit it to the tag. Also working version will be incremented and updated to "-SNAPSHOT" again, e.g. "1.0.2-SNAPSHOT".
This can be followed by a call to release:perform. For more info see example
release:perform
Perform a release from SCM, either from a specified tag, or the tag representing the previous release in the working copy created by release:prepare. For more info see example
--batch-mode allows a non-interactive script executeion. For details please read about maven-release-plugin
Use the maven release plugin to handle incrementing the version number. At that point all you have to do is have the Jenkins build run maven with the release plugin goals.
Here is a good article on it.
http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/
With that all you have to do in Jenkins is have it run the following command on the checked out repository.
mvn release:prepare release:perform -B

maven release:branch - where to perform?

I tried today to switch our release build so that it uses branches. Before my change, I just did
mvn release:prepare -B -Dusername=$SVN_USER -Dpassword=$SVN_PASSWORD -Dtag=$RELEASE_VERSION -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$NEXT_DEV_VERSION
mvn release:perform
Now I changed to use
mvn release:branch -B -Dusername=$SVN_USER -Dpassword=$SVN_PASSWORD -DbranchName=$RELEASE_VERSION -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$NEXT_DEV_VERSION -DautoVersionSubmodules=true -DbranchBase=$SVN_BRANCH_BASE -DdryRun=false -DsuppressCommitBeforeBranch=false -DremoteTagging=false -DupdateBranchVersions=true -DupdateVersionsToSnapshot=false -DupdateWorkingCopyVersions=true -DgenerateBackupPoms=false
then I checked that branch out and tried to perform a release on it. But this does not work, it tells me:
Unable to configure SCM repository: No such provider: 's'
SCM config is:
<scm>
<connection>scm:svn:https://svn2.mycompany.com:8443/svn/polyalert/branches/02_Los_1/releases/0.01.9</connection>
<developerConnection>scm:svn:https://svn2.cmycompany.com:8443/svn/polyalert/branches/02_Los_1/releases/0.01.9</developerConnection>
<url>https://svn2.mycompany.com:8443/svn/polyalert/branches/02_Los_1/releases/0.01.9</url>
</scm>
This url might look a bit strange, but we do not have a default layout and this is a correct branch URL.
This is done with maven 3. I´m not sure if it´s correct to do the release:perform in another location than I did the release:branch, but I don´t have a better idea, specifically because I can not set any release.properties file like it is created with release:prepare. Or would it be necessary to do the release:branch AND the release:prepare? A first try on that did not work and got the same error.
Any suggestions?
Thanks
Michael
After lots of struggle, I found the following approach working:
Ensure that your trunk has definitely correct scm info in the pom.
run mvn release:branch -B -Dusername=$SVN_USER -Dpassword=$SVN_PASSWORD -DbranchName=$RELEASE_VERSION -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$NEXT_DEV_VERSION -DautoVersionSubmodules=true -DbranchBase=$SVN_BRANCH_BASE -DupdateWorkingCopyVersions=true.
This will create a branch in SVN where all versions are kept like they are in the trunk and will then increase version number in the trunk to $NEXT_DEV_VERSION and commit this as well. Branchbase can be set in the plugin configuration as well (in this case it can be omitted here).
checkout the new-made branch and change into the local branch dir
run mvn release:prepare -B -Dusername=$SVN_USER -Dpassword=$SVN_PASSWORD -Dtag=$RELEASE_VERSION -DreleaseVersion=$RELEASE_VERSION to update the release number in your branch to $RELEASE_VERSION (will be changed locally + commit into the branch by this single command). This command will on top create a release tag.
run mvn release:perform in your local branch dir to start the actual build. This will checkout the tag created in the previous step and build upon this code.

Resources