How to conditionally run maven-release:rollback in jenkins? - maven

I am using jenkins/hudson to make maven releases, and sometimes when the builds fails, I have no other way that manual to rollback and then start the jenkins build again. I was wondering if there is any good and configurable way of running mvn release:rollback in the end of the build dependent the result of mvn release:prepare? I mean, if the release process fails, I want to run maven release:rollback, otherwise not.
Thanks your time.

You can configure your Jenkins job to do a fresh checkout of the source code every time the job is started. So if your release fails before the creation of the release tag, you can fix the problems and just start the release again.

Related

Running maven release on a successfully build - jenkins

I need to be able to run a maven release procedure in the following way.
A manual jenkins job will be triggered, the maven release will build the artifacts according to the argument and the build procedure, in case it passes i want the job to trigger additional tests by calling other jenkins job, and only in case all passes to deploy it to artifactory.
Is this possible? or are there any better alternatives..?

Make Jenkins Build a SUCCESS After successful Spring-boot run

I have CI system using Jenkins that automatically clones a repository,
then runs mvn clean install and then mvn spring-boot:run (using windows batch).
My problem is that the Jenkins Build does not stop even though the spring-boot:run is successful.
Is there any way to work this out?
I found a workaround for this.
I added a Build Step that executes a Windows Batch file as a child process
but before starting the batch process, I changed the BUILD_ID to something like BUILD_ID='NO_DELETE' so that Jenkins won't automatically kill it.

Can I run integration tests from Mvn (Failsafe Plugin) against different versions of a branch easily?

Say my mvn Project has had a major version release.
So trunk is version 2, and I have a branch with Version 1. I want to allow developers to freely edit tests on trunk, But I would also like to maintain backwards compatibility from version 2 to 1. Is there an easy way to run version 1 branch integration tests against version 2 source code. I was thinking of compiling and moving the test jar (not sure if this would work), but that seems ugly.... Just to clarify, unit test classes are denoted with Test.java where as integration tests are denoted with IT.java. I only want to run the integration-tests
I would preferably be able to run something like
mvn integration-tests -Dfailsafe.plugin.src="branch/version1".
Alternatively, a Jenkins or Atlassian bamboo plugin would work.
Simply switch branch before executing mvn failsafe:integration-test. This is common pattern.
Maven Failsafe Plugin has no support for switching branches and no support for Version control systems (VCS) - and this is good, because this other plugin responsiblity.
This is easy to switch branch in tools like Jenkins. Create one job per branch, changes to code in branch should trigger jenkins build. Jenkis has support for private maven repositories, this will help with artifact collision. Also is possible to share workspace (results) from first job with second job.
In your case build job pipeline in jenkins, after first job from master execute job from branch to verify integration tests.
The best idea I've seen so far is to do a switch on the version control system and then just to run the integration tests.
Steps
svn co trunk
mvn clean install
svn switch branch
mvn failsafe:integration-test
If you run mvn integration-test in this stage you will rebuild the project and you will thus be testing your branch/the older version
I have coded this up and tested it against svn/mvn/jenkins stack

Is it possible to have a maven build write a file when it fails?

I have a maven build running in a Jenkins job.
I need to do some post-processing stuff after the maven build but during the job, and so I'm running mvn with the -fn (--fail-never) option (jenkins will halt the job immediately otherwise).
The catch, of course, is that if the maven build step failed, I need to fail the job in a subsequent build step.
In the past I've done this sort of thing by writing a file to a certain location if the build failed, and then using the Ant task to fail the build. So this is the approach I'm going for.
Is it possible to get maven to write a file on build failure?
Instead of using the maven runner in Jenkin, you could execute the build as a shell script, then do something like...
mvn -q -fn clean verify || touch build_failed
I would suggest to use the configuration jenkins is capable of. Running a post-build-action in case of successful execution of the build and don't use --fail-never option.

Maven plugin execution change Maven properties or skip build lifecycle steps

When I build my application with maven, I run mvn clean install. As a part of the install lifecycle, I run appengine:devserver_start from Google's GAE Maven plugin. This appears to be already bound to a step in the lifecycle and therefore it reruns some build steps from the beginning, even though me running mvn install did those. For example, the resources step is rerun. I had my own Java script run to download the latest resources for my build. But because of appengine:devserver_stop, I need to uselessly run this cript again because the resources step is re-executed.
I can think of two ways I can avoid this, but I'm not sure how to configure both ways. The first would be to somehow skip re-running build steps that I've already run. The other way would be to change the Maven POM properties just for the plugin execution. I have a Maven property set, either to true or false, that I can use to set the skip setting for the Java script I use during resources (because I run this script using the exec-maven-plugin). Think of this as a Maven property that can be set with the -D flag. Can I have this property changed just for the plugin?
If you are having trouble thinking about my scenario, consider what happens when you run mvn compile install. All build lifecycle steps until compile will run, then all compile steps until install will run, including compile.
A common/easy way to solve this kind of problems is to use maven profile. Just create a new profile that includes the plugin with preferred phases.
You should probably don't fight with it and just run clean appengine:devserver_start instead of clean install. Read my answer here for a more detailed explanation:
https://stackoverflow.com/a/17638442/2464295

Resources