I have a Jenkins Pipeline which runs per commit, does a build and runs some sanity tests.
Then at 8pm I want the latest successful build to carry on and run more indepth tests as part of the same pipeline.
I have looked at milestone and lock but it seem that the first commit of the day would grab the lock to wait till 8pm and then be "promoted" and then when that finished it would run the latest which doesnt work for me.
I have looked at milestone and then having a user-input to hold all the builds at the end of the first stage, but that would mean manually clicking a job at 8pm or having and external script to do it.
I've also looked at checkpoint and this doesnt appear to have the ability to do what I need either.
Can anyone suggest a groovy method for a new build to supersede an old one or plugin that would work for me?
Related
I have a declarative pipeline that executes almost regularly.
Upon specific condition (evaluated during the job run) I'd like to keep the job longer than usual.
Usual runs I keep for one week.
If condition 1 is true I want to keep the build for up to a month.
If condition 2 is true, I want to keep the build for up to six months.
Can Jenkins do something like that out of the box, or can it do it by adding some plugin?
So I found a solution to this job: Jenkins out of the box cannot do what I was searching for. However Jenkins can run plugins. Not finding any plugin that would satisfy my need I started creating my own. Here are the highlevel steps if someone wanted to do the same:
follow the Jenkins Plugin development tutorial. From that you have a plugin with a build step and a build action
modify the build action to store the information about the two conditions, or even better the resulting keep period.
modify the build step so the information can be set from freestyle builds or pipeline steps.
create a BuildDiscarder that reads the information from the action and honors it before triggering a delete
I need to schedule a Jenkins task so it runs once per day, but only if certain other tasks succeed at least once that day. That situation makes it similar to this other question, but none of the answers there describe how to deal with the contingencies I have.
My team has a Jenkins process that builds the software. We'll call that the Builder. Builder checks our GitHub repo every 15 minutes and runs if it sees a code change.
We have another task that runs simple tests. This entire test suite can finish in less than 15 minutes. This is the Short-Tests task. Short-Tests run every time Builder passes.
Lastly, we have a set of tests that take hours to run. Let's call these the Long-Tests. We want to run this once per day, but only if Builder and Short-Tests both pass. The Long-Tests start late at night so we can check the results the next morning.
Furthermore, we want to run Long-Tests only on the most recent successful build that day. If the most recent build failed, we want Jenkins to ignore that build and test using a previous build that passed.
If no builds pass that day, there is no need to run Long-Tests at all.
I can schedule Long-Tests for once per night like this, but please tell me how to set up the dependencies.
01 00 * * *
In order to get this behavior you need some kind of persistence to flag successful build and successful short test completion. There are several options available depending on your actual setup such as:
File based flag (writing to file on successful build / test)
Database flag (writing to database on successful build / test)
Git branch manipulation (pushing/merging to specific branch on successful build step, such as example given here: http://andrewtarry.com/jenkins_git_merges/).
Once you have your persistence setup, you can trigger builds either on change or periodically. For example following dependencies can be setup:
Push to Git code branch, triggers Jenkins Build job
For this step you need persistence, say pushing to git: Upon successful completion of build stage, short tests are triggered and, If successful, push to git "latest passing short test" branch is executed using Git Publisher plugin for example. This is to ensure that only last passed short test are going to be scheduled for long nightly tests.
Lastly, long tests are scheduled periodically, handling branch "latest passing short test".
This is just top level overview, since details depend a lot on your actual setup, permissions, git policies, type of Jenkins configuration etc.
I have just setup a basic multibranch pipeline build job and have a feature branch with a jenkinsfile present which I am experimenting with.
I have the job configured to poll the scm every 5 mins and trigger a build if necessary.
I am finding however at times when I manually start a build for my branch after I have pushed up a tweak on my Jenkinsfile for example (as I don't want to wait for the next scm poll interval), the branch re-indexing activity can still trigger another build to be performed.
See the image below for what I mean, so here build 7 is one I kicked off manually on jenkins, so it picked up my commit, but then the branch indexing kicked off build 8 but there were no new changes for the branch.
Is there a way to prevent this from happening? Other than me being patient and waiting 5 mins of course!
Thanks
I experienced this also. I tried playing with the polling settings in the Multibranch pipeline to see if this could fix it but that only led to no builds being spawned at all in response to SCM changes.
So this behaviour to which you refer was the best of a bad lot.
At time of writing, I think this behaviour is a bug with no current resolution.
Can't remember if I raised a ticket or not as I am in Azure DevOps world now.
I have a long-running job (10 hours) scheduled to run twice a day (at 11am/11pm).
I generally only want to commence the build at 11am/11pm.
If the previous build fails, I sometimes want to start the next build early (e.g. 9am).
How do I do it? If I manually kick off the build at 9am, the scheduled build will go into the queue at 11am, and will execute as soon as the first build completes. I don't want that, if I manually start, I want to skip the scheduled build.
Another way of thinking of it ... I want to ignore a scheduled (or manual) build request if there is a build in progress.
To do what I'm wanting I've added the following into conditional build steps at the start and end of the job, conditional on the Build Cause of UserCause.
jenkins.model.Jenkins.getInstance().getItem('Test').disable();
jenkins.model.Jenkins.getInstance().getItem('Test').enable();
Peter,
https://wiki.jenkins-ci.org/display/JENKINS/Run+Condition+Plugin
Above plugin will be useful for you.kindly go through the documentation.
Try this Plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Block+queued+job+plugin
It will allow you to block job when last build is in progress.
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?