Jenkins - API to update build status - jenkins

I am using Jenkins to build my project. When the build is ready, the product is downloaded and tested. I would like to notify Jenkins that the build is tested and then to notify it about the test results. I would like that once jenkis has created the build, it is available to download, but that there is a message like 'build is tested' or 'tests passed/failed'.
Uploading a file with this kind of information would be OK as well.
Is it possible with jenkins?
I do not want to integrate my tests into jenkins build process: they take too long and use too much resources (and must be carried out on a separate machine with dedicated environment)

You can setup 2 promotions on the build job. Call one "Tests Passed" and another "Tests Failed".
The promotions will add different colored "star" icons to the individual builds to indicate which promotions had been executed. All build artifact downloads and other build information is available regardless of promotion status.
If you will be "notifying" Jenkins manually, you just need to manually execute a promotion. You can also access a permalink to the last successful promoted build's artifacts like http://[JENKINS_URL]/job/[JOB_NAME]/[PROMOTION_NAME]/artifact
If you want your test process to notify Jenkins automatically, you would need to trigger it by sending a call to the webpage. You can use CURL to request http://[JENKINS_URL]/job/[JOB_NAME]/[JOB_NUMBER]/Promotion/[PROMOTION_NAME]/build. Of course you need to know the number of the build that you are trying to mark for promotion. Alternatively, you can use the "Last Successful" permalink like http://[JENKINS_URL]/job/[JOB_NAME]/lastBuild/promotion/[PROMOTION_NAME]/build

Related

Trigger a downstream project on demand

Given the following situation
main-job builds and tests a project
installer-job copies artifacts from main-job, and packages them into an installer
installer-job is set as downstream project of main-job via Parameterized Trigger Plugin.
But the installer-job should only be triggered on-demand from main-job's build page.
It's possible to trigger the downstream job on the project page:
But it doesn't seem possible to trigger the build from a specific build page.
Is there any option to get such a trigger button on the build page?
Note: It's a freestyle project, not a pipeline one. So things like the Build Pipeline plugin don't help, unfortunately.
An elegant solution is possible via the Promoted Builds Plugin. "Promotion" is some activity that's performed when a build fulfills certain criteria, like
build was successful
all downstream builds passed
explicit, interactive confirmation
In your case, this condition will be simple: just "main-job" needs be successful, and you will want to confirm explicitly.
There's lots of possible steps that can be triggered as promotion activity -- what you want is to trigger a build of the "installer-job", which can be configured easily.
To summarize, for "main-job", you will configure something like this:
When you do that, the 'main-job" builds will feature a "Promotion Status" button. After pressing the "Approve" button there, the promotion will be enabled and the "install-job" will start building:

Run Jenkins job all the time

I've a Jenkins job I want to keep running all the time. When a build is ending, I want to immediately trigger another build. How can I do that?
Thanks, Omer
There are two different job configurations for that:
Build Triggers -> Build after other projects are built
Add a post-build action Build other projects
In both cases, you can enter your own Project, so it'll be triggered again every time a build is completed. You can also specify if this should be done only while the project is stable.
There is however one (probably more) drawback in this approach, which is that it'll create enormous overview pages, where all build triggers are listed:
So i'd recommend to do something else and for example use the Jenkins API to trigger a new build. There are many ways to do that, one simple example is adding a build step Execute shell and do something like:
curl -X POST http://localhost:8080/job/$JOB_NAME/build
If you have configured the Jenkins URL, you could also use $JOB_URL. You can also add post parameters to trigger a parameterized build.

Promoted Build Plugin , can not see Promotions

When I am running the Jenkins Job with promotion setup like below ,
I cant see my promotions after the build is completed in the UI .
Please suggest if I am missing something.
Builds that had finished before the promotion was originally created are not "promotable"
Run a new build, and it will show.
Note: this restriction is only on the creation of a new promotion. You can modify the promotion process as much as you need, and it will be executable on older builds without problem (as long as those builds had finished after the original promotion was created)
Edit:
I think I misunderstood your question. It appears you are on the "Promotions History" page, the one at http://$JENKINS_SERVER/$JOB_URL/promotion/. You won't see builds here until they have been triggered for promotion.
To actually trigger a promotion on a build, you have to select the specific build number/job run. Promotions are per job-run, not per job. Each job run has associated promotions with it.
You need to be at http://$JENKINS_SERVER/$JOB_URL/123/promotion/ where 123 is the build number that you want to promote. You can use permalinks instead of 123, such as lastBuild or lastSuccessfulBuild, etc.
To reference to 123 from within the build (in order to use this in email notification links, etc), you can use $BUILD_NUMBER variable.
Through the UI, you need to select a build from the build history, click
"Promotion Status" there, and then approve/trigger a promotion (I know it's confusing since both "history page" and "trigger/execution" pages have the same name for the link.)
First you have to promote the build then you can see that particular build in promotion status.
First click on build number that you want to promote then click click on promotion status from late panel. Here you will see the user who can promote the build.
Then you have to approve it for the promotion.

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.

Jenkins Test Result History

At the moment we have our Jenkins Jobs configured so the Test Results get written to a specific file and then published. The problem with this is the next time the build runs it replaces the previous test results. This means the link the the email notification points to the same test results file and we are not able to debug why the tests failed.
Is there a way to create test results with a unique name like a time stamp and publish these?
You can use the archive function of Jenkins. Add the post build action "Archive artifacts" to your job and give the filename pattern of your test file. Now the file is archived for every job. The link in the mail notification may still point to the newest file, but you can download the archived files in the web interface of Jenkins (if you go to a specific build, you see all archived artifacts of that build).

Resources