Retry Jenkins Maven build if unstable? - maven

Might be a very basic question, but I can't seem to find any straightforward documentation on how to do it.
I have a very basic UI test that runs every couple hours, and every once in a blue moon the build is unstable because the test fails for one reason or another(finicky selenium stale elements, other anomalies). I would like it so that that the job retries the build again if it is unstable, and if it is still unstable after the second try, then send out the alert (currently using Slack notifications in the post build actions section).
Is there a way to do this? Thanks in advance!

The naginator jenkins plugin allows you to rerun a build for unstable builds as well as failures. You will have to install the plugin in jenkins.
https://wiki.jenkins.io/display/JENKINS/Naginator+Plugin

Related

Is there a way to get notified (email, desktop notifications etc.) after my maven clean install is completed in IntelliJ?

I have a maven build that if successful takes couple of hours. However if it fails abruptly, i have no clue until i get back to IntelliJ and see what happened. Is there a way to get notifications regarding my run/build status from Intellij so i get to follow up right away?
First of all, it would be good to analyse why this build takes so long. Then one could find possible speed-ups.
Secondly, making such a build is a job for a build tool like Jenkins, not for IntelliJ. Jenkins can inform you about failed or succeeded builds.
Since the IDE is a desktop app it notifies about build status on build completion in status bar:
As for other means of notification I think Fabian's answer is right.

Jenkins Conditional Deployment

I am using Jenkins to create nightly builds and deploy them to my maven repository. In order to reduce the daily bandwidth for developers I want to change the deployment logic so that it's only deployed if changes with reference to our latest deployment are detected.
I found some plugins that seem to be suitable, but since I'm not too involved into the Jenkins use-ability I wanted to ask if there is an "easy" way to implement this?
I thought about some simple test before executing the deployment process:
Check if there are changes made within the project code or the dependencies
=> NO: then nothing should be deployed
=> YES: deploy the new version
I just stumpled over the Conditional BuildStep Plugin. But I'm not sure if this plugin fits best for our approach. I don't want to mess up the whole configuration.
FYI: I am using Jenkins 1.608, Tortoise SVN, and the deploy-Plugin 1.1
Every answer and help is highly appreciated!
Setup your job to run nightly (current configuration)
Setup a conditional build step (shell or batch, depends on your OS) that will check the revision number in repository and compare to current revision number in workspace.
If not higher, quit the build.
If higher, continue build as usual
Edit:
To avoid the build even being triggered, here is a theoretical solution.
Install Poll SCM Now plugin, this will add a "poll now" button to the job, that polls SCM for changes. If changes found, a build is triggered, if not, nothing happens.
Configure the polling permissions to anonymous users (else you'd need to implement login/token in next steps)
Configure the job to poll SCM infrequently (like once a year)
Configure a cron job (or a scheduled task in Windows) for a nightly schedule
Have that cron/task do a curl or wget to http://JENKINS_URL/JOB_URL/poll

Pause TeamCity projects while others are executing

I’d like to be able to specify that one build project should pause while another specified project is running.
In my case, there is a project #1 that builds and deploys compiled code to our servers, and a project #2 that performs Selenium tests on that deployed code. The tests can take several minutes, and I’d like to make sure that the build-and-deploy doesn’t happen in the middle of testing.
So, I’d like to pause #1 (build) while #2 (test) is running.
Dependencies or Triggers do not offer this option, as far as I can tell. Can this be configured?
There is a request on TeamCity issue tracker TW-3798. You are welcome to vote and watch.
This functionality is currently being developed. For now you can use one of the features provided by GroovyPlugin called StartBuildPrecondition. To ensure that only one build is executed add the same write lock to both of the builds
The way we do this is by restricting them to one build agent. They you are insured that only one runs at a time.

how to time (profile) maven goals in a multi-module project

We have a huge project with many submodules. A full build takes currently over 30mins.
I wonder how this time distributes over different plugins/goals, e.g. tests, static analysis (findbugs, pmd, checkstyle, etc ...)
Would it be possible to time the build to see where (in both dimensions: modules and goals) most time is spent?
The maven-buildtime-extension is a maven plugin that can be used to see the times of each goal:
https://github.com/timgifford/maven-buildtime-extension
If you run the build in a CI server like TeamCity or Jenkins (formerly Hudson), it will give you timestamps for every step in the build process and you should be able to use these values to determine which goals/projects are taking the most time.
I don't think there is any way built in to maven to do this. In fact, in the related question artbristol posted, there is a link to a Maven feature request for this functionality. Unfortunately, this issue is unresolved and I don't know if it will ever be added.
The other potential solution is to write your own plugin which would provide this build metadata for you.
I don't think there is a way to determine the timing of particular goals. What you can do is run the particular goals separately to see how long they take. So instead of doing a "mvn install" which runs all of your tests, checkstyle, etc.. just do "mvn checkstyle:checkstyle" to see how long that takes for a particular module.
Having everything done every time is nice when its done by an automated server (continuum/jenkins/hudson) but when you are building locally, sometimes its better to be able to just compile. Some of the things you can do are have the static analysis goals ONLY run when you pass in a certain parameter or profile. Another option is to only have them ran when maven.test.skip=false.
If you are using a continuous build, try having the static analysis only done every 4 hours, or daily.

What's the workflow of Continuous Integration With Hudson?

I am referred to Hudson today.
I have heard about continuous integration before, but I have no idea what the heck is a ci-server.
Hudson is really easy to install in Ubuntu and in several minutes I managed to set up an instance of it.
But I don't quite understand the workflow of a ci-server, or how am I supposed to use it?
Please tell me if you have experience about ci, thanks in advance.
Edit:
I am currently using Mercurial as my SCM, and I wonder what is the right way to use it with Hudson.
I have installed the Mercurial Plugin of Hudson, and I create a new job with a local repository. When I commit in the repository the Hudson job is built with the latest version of my source code.
If what I used is a remote repository, what's the workflow like?
Is it something like the following?
Set up a Hudson job with the repository
Developer makes a local clone of the repository
Developer commit and push changes
The remote repository update with the incoming changeset
Run a Hudson build
There may be something I misunderstanded at all, please help me point it out.
Continuous Integration is the process of "integrating software" continuously i.e. as frequently as possible (ultimately after each set of changes) to avoid any big-bang integration and all subsequent problems by getting immediate feedback.
To implement Continuous Integration, you first need to automate the build of your software (where build means of course compiling sources, packaging them, but also compiling tests, running the tests, running quality checks, etc, anything that will help to get feedback on the health of your code). Then you need to trigger the build on the latest version of the sources on a particular event (a change in the repository, a temporal event), to generate reports and to send notifications upon failure (by mail, twitter, etc).
And this is precisely the responsibility of a CI engine: offering trigger mechanisms, being able to get the latest version of the sources, running the build, generating and publishing reports, sending notifications. CI engines do implement this.
And because running a build is CPU and Disk intensive, CI engines usually run on a dedicated machine (or even a farm of machines if you want to build lots of projects).
Back to your question now. Once you've got Hudson running, configure it (Manage Hudson > Configure System): setup the JDK, build tools, etc. Then setup an Hudson Job and follow the steps: configure the location of the source repository, the build tool, the trigger, a notification channel and you're done (you can do more complex things but that's a start).
For more details on the setup, check:
The official Use Hudson guide for more details. << START HERE
Continuous Integration with Hudson - Tutorial.
Spot defects early with Continuous Integration.
Martin Fowler's overview of continuous integration is one of the canonical references. In my opinion, using automation to make sure your code base is healthy is one of the most useful things that you can set up.
Update Sorry that I didn't have much time earlier to expand on my reply. #Pascal_Thivent is right that in order to effectively use CI, you need to be able to automate your builds, tests, etc. CI is actually a good forcing function for this. For me, it's one of those little warning flags if I start to think that it would be too painful to put a build into Hudson. It means that something is not quite right.
What I like about Hudson is that it's flexible enough to accommodate different workflows. We use it for both builds / unit tests and releases. And it eliminates a lot of the worry about certain release procedures only working in one person's environment.
What I don't like about Hudson is that it is occasionally unstable when new builds break plugins. I've had a couple of upgrades (2 out of 10 or so) go bad because of incompatibilities. I do two things now:
I never upgrade my team's Hudson server to the latest and greatest right away. I generally only upgrade when there are significant new features, or bug fixes.
I now have a basic Hudson instance set up with all my plugins on a virtual machine with some dummy builds that I fire up to test out any new upgrades before doing it on the public server.

Resources