Sonarqube: reordering published build results - jenkins

I am publishing build results to Sonarqube, with jenkins.
Each commit on git is triggering a jenkins build.
My problem is that build duration is not deterministic so build #2 can finish before build #1.
Consequently, results are published to Sonar in wrong order and differential view shows wrong results.
For example, if i corrected a unit test in build #2, results of buildĀ #1 will tell me that test is failing again.
Build result version is setted and it should be used to order builds instead of publication date.
Is there any way to do it?
Thank you.

The SonarQube platform is going to process the analysis reports in the order it receives them. It has no way of knowing anything about your Jenkins build number.
Your best bet is to enable the Throttle Concurrent Builds option to make sure that each new job waits its turn. That's the only way to ensure the order you expect.

Related

TFS Chained Gated Check In Builds

Currently my TFS 2012 build environment features a Build Verification (BVT) build which mostly follows LabDefaultTemplate.xaml worfklow. The BVT build first queues a Continuous Build (which mostly follows the DefaultTemplate.11.xaml), waits for that build to finish, then performs the necessary tests.
Now, I would like to change this BVT build to be Gated Check-In. Which is to say, I don't want any changes to be committed until the BVT is successful. The problem seems to be queuing the Continuous build definition in such a way that it will pick up the shelf set. This logic appears to be dependent on the build being started with Reason = "CheckInShelveset". However it seems all builds queued from another build always have Reason "UserCreated". Has anyone found a way around this problem? Is it possible to chain builds together while still having Gated Check-Ins?

Jenkins: Starting a build without permanently recording the result

I'm trying to tweak some options in my jenkins configuration, which is causing many builds to fail. I'd prefer to not keep these failures around in the build history, since they're not technically failures of the repository. In the past, I've just deleted the build after looking at the log, but this is a little tedious.
Is there a way to start a build with an option to not record the result of the build permanently?
Perhaps there's a URL that can be used to trigger a debugging build, somethign like:
JENKINS_URL/job/JOBNAME/build?DEBUGGING
You can set the "discard old builds" option in your job to only keep 1 build. If you have older builds you want to keep, you can give them the "keep this build forever" property. If you have a large number of jobs to work with, you can use the Configuration Slicing plugin to modify the Max # of builds to keep.

In Jenkins, can I trigger a downstream job once a day

We've got a Jenkins setup where we do incremental builds on SCM change, validate and then if this works do a full build (from scratch). This basically works but we waste time doing full builds during the day that we don't normally use.
I know we could trigger full builds every night, but many of our branches won't change for a few days - and then we might get a rush of changes. Thus building every branch every night is wasteful too.
What I really want is some mechanism where we only do the full builds once (say at night) if there has been an SCM change and the incremental build and validate worked - there is no point auto-triggering full builds where the incremental build and validate failed. Actually just "the incremental build and validate worked" should suffice - as these normally just run on SCM change.
Any suggestions? Is there some Jenkins extension that would help with this?
To achieve what you've asked for you can create a new job that is the same as your existing one, but have it only poll the SCM once a day, for a nightly build.
Set the schedule to something like this: H H(0-5) * * *.
In your original job, remove the post-build triggering of a full build.
That will give you pretty much what you've asked for, except the nightly build will do an incremental build and then a full build if the incremental one succeeded, rather than just checking the result of the last incremental build.
BUT...
What is the cost of the 'waste' you are trying to avoid? How much does running a full build every night actually cost you? And wouldn't you be better off finding out when the full build is broken as soon as possible, i.e. during the day when it was broken rather than only the following morning?

How do I get all build steps to execute in Hudson/Jenkins?

I'm using Jenkins to build a number of client libraries to my system, each one targeting a different language. My configuration consists of a number of distinct build steps, one for each language, building and/or testing the library.
Right now, a breaking change in the system will cause the first build step to fail, and no other build step ever gets run, which is very inconvenient. I need to run all build steps, so that I can see all resulting errors.
One alternative would be for a configuration to exist to tell jenkins not to abort latter build steps if earlier ones fail. I didn't find any such thing, but maybe there is.
Another alternative I thought of was to trigger each language as a separate build, but then I have to tie them all up for my post build steps, and I'm not sure how to do that.
And, of course, there might be something I'm missing.
Any of the above would solve my problem. So, what should I do, and how do I do it?
The Multijob Plugin is what you are looking for. I use this plugin a lot. Take a look at their screenshots - You can specify three options on how to mark a Phase(a Phase can have multiple jobs) as successful
when the Phase Job's build was successful
even if the Phase Job's build was unstable
even when the Phase Job's build failed - this is what you need
In your case, you can create a Multijob Job that has one phase for each 'client library'. And add your respective 'client library' jobs into their Phrases. So if you have 10 'client library' jobs then you will end up having 10 Phases (one for each) in this MutliJob. And don't forget to set the 'Mark phase as successful when phase jobs' statuses are' as 'Complete (always continute)'
I usually don't prefer using Downstream Jobs for this purpose, because, there is no nice UI in Jenkins to look at the whole build flow in a single page. Ofcourse there is this Build Pipeline Plugin that shows each and every build flow status. You may choose the right plugin based on your need.
To make this work in one job, I think you need to make the build steps to not fail (return non-zero exit code). Then you need a post-build step which analyzes test results and marks build failed or unstable, if needed.
You may need to write a wrapper script to do the build, such as simple .BAT or shell script, which has exit 0 as last line, after running the build/test actions.
Example of a post-build action which does this kind of test result processing is Publish JUnit test result report.

Manually failing a build after it's complete

Is it possible to set the build result for a build after that build is complete?
I could not find any plugins that do this already, and I was considering writing my own, but I wanted to see if this was even possible before going down that path.
(I have looked at existing code and how the "Fail The Build" plugin works as an example, but my understanding of the Jenkins code base is not advanced enough to understand what all the possibilities are.)
Use case: we have a build pipeline, and near the end of the pipeline there is a deploy-to-qa step that deploys the artifact to a QA environment. We have automated tests before this step to try to catch any problems with the artifact, but our test coverage is not very high in some areas so bugs could still slip through the cracks. I'd like to have the ability to mark a deploy-to-qa build as FAILED after the fact, to denote that that particular pipeline was invalid and is not a candidate for production release. (Basically the same as this Build Pipeline Plugin issue)
After some more investigation in the code, I believe that this is not possible.
From hudson.model.Run:
public void setResult(Result r) {
// state can change only when we are building
assert state==State.BUILDING;
// snip
...
}
So the build result cannot change except when in "building" state.
I could try to muck with the lastSuccessful and lastStable symlinks (as is done with the delete() function in hudson.model.AbstractBuild), but then those would be reset as soon as Jenkins reloaded the build results from jobs/JOBNAME/builds/.
I have an untested suggestion: Make a parametrized build, where the parameter determines if build will fail or not (for example simple bat / shell script testing the parameter from the environment variable it sets, and doing exit 0 or exit 1). This assumes that build pipelines manually triggered step will ask the parameters, and not use default values.
If it does not support interactive build parameters, then some other way is needed to tell this extra build step wether it should fail or not. Maybe editing upstream build description or display name to indicate failure, and then allowing build pipeline to continue to this extra build step, which probably has to use system groovy script to dig out upstream build description or display name.
I have seen several debates on this topic previously, and the outcome was always that it is theoretically possible to do so, but the codebase is not designed to allow this and it would have to be a very hacky workaround.
It's also been said that this is a bad practice in general, although I don't remember what the argument against it was.
I am facing the same requirement. I haven't found an appropriate plugin, changing the build status is not just a flag but has other impacts on links (eg latest successful build etc). So instead of changing the status of the build I looked for a possibility for qualifying the build. The Promoted Builds Plugin apply flags to build to define e.g. different quality stages. Build promotions can be performed manually or based on e.g. downstream project successful builds. Any successful build can be qualified, based on the promotion additional build and post build actions can be executed, e.g tagging or archiving.
Actually I was able to do it by changing the build.xml manually to <result>FAILURE</result>.
I've then played a little bit with mklink to create some symbolic links and also renamed the lastSuccessfulBuild to lastFailedBuild and it worked. If you are allowed to access the filesystem from within a Jenkins PlugIn, then it is possible to write one.
In case you are fine to delete the current build and start the same build using a version number and setting the next BUILD_NUMBER to the deleted one, then you could use this plugin to tell it to fail instead of succeed:
Fail The Build Plugin

Resources