How to run Jenkins pipeline continuously?
The pipeline is started and once it's finished it runs again and so on
I tried */1 * * * * to run every minute but it's not waiting until the previous pipeline is finished but I need to wait until finished and only after it start running it again
You can disableConcurrentBuilds() in your pipeline. This will prevent it to run till the previous ones complete.
Why not trigger a new run of the pipeline as a last step (or a post step depending on a condition if you need to) of this same pipeline?
See the build step to do so: https://www.jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job
Related
I have a requirement to run a destroy job (which will destroy the instances) after testing. The testing will take around 1hr. So the instances can be destroyed after that, adding some leisure time, say after 2hrs.
Jenkins file
Run job-1
Run job-2 - deploy in lower environment
Run job-3 - destroy lower environment after 2hrs of current-time
Run job-4
Run job-5 - after 3hrs
All the jobs should run one after another without wait. And there I am stuck !!
timer - will wait until the given time completes and abort :(
sleep - will wait until the given time and runs next job/whatever :(
trigger - will trigger the job but with cron functionality :(
I am ok to use trigger if my requirement can be accomplished with it.
Or any groovy code to set trigger time (set cron time [currentTime + 3hrs])!
Or
simply - I want to run a cronjob ONLY for one time [just after 3hrs of Now]
Note: I am a newbee to groovy
Use Quiet period set to 120 mins for the last job - Job-5
Groovy syntax is build job: 'Job-5',quietPeriod: 120, wait: false
Jenkins version 2.121.2
I have a multi-branch pipeline set up. I am using a declarative Jenkinsfile.
I have a set of tests which take a long time to run. I want these to run over night for any branches which have changes.
I have tried a few things but my current failing attempt is:
Under the job > configure, I have enabled 'Suppress automatic SCM triggering'
Have 'Scan Multibranch Pipeline Triggers' > 'Periodically if not otherwise run' set to 1 minute (just for testing, I will increase this when it is working)
In my Jenkinsfile (example for a 4am run), I have also tried with pollSCM():
triggers {
cron('0 4 * * *')
}
In the 'Scan multibranch pipeline log' I see the following but no job runs at 4am (time in the trigger() in my Jenkinsfile):
Changes detected: my-feature-branch (1234567890abcdefgh → abcdefgh123456789)
Did not schedule build for branch: my-feature-branch
What am I doing wrong please?
Edit:
So I've tried this set up instead:
Set the cron to every 15 minutes
triggers {
cron('5,20,35,50 * * * *')
}
Removed the setting under configure in the UI 'Suppress automatic SCM triggering'
But it just starts running the minute polling has happened (16 minutes past the hour in this test).
What ever I do nothing seems to pay attention to my cron settings?
If I got to 'View configuration' under the branch job in the UI it shows the UI settings from my Jenkinsfile ok.
Edit (again!):
So with the last edit, it did actually run immediately and then again at the cron time.
Now enabled again in the UI the setting 'Suppress automatic SCM triggering'.
And I have it working! The main issue I realised (a) changes are not applied I do not think until the run after the first run with a change in the Jenkinsfile? (b) Also I installed the next execution plugin so I can see what it is planning on better.
The issue here was that trigger declared in multibranchPipelineJob is for scanning multibranch. To run job periodically declare trigger in pipeline like this:
pipeline {
triggers {
cron('45 6 * * 1-5')
}
agent {
...
I have one pipeline build called, for example UAT. This build is scheduled every 3 minutes. And another build called DEV. DEV is scheduled every minute. The task is: to run UAT only if the last DEV execution was SUCCESS. If not - skip the execution. And run it after other 3 minutes with the same condition.
How can I achieve that ?
Don't schedule your UAT job as a separate job but instead trigger the launch once your first DEV pipeline finishes with success.
As you are using pipelines you actually have 2 solutions :
1)
Don't call another job but just call a Groovy function to integrate the DEV part, such as :
node() {
stage "UAT"
// Your existing UAT pipeline content here
stage "DEV"
git 'http://urlToYourGit/projectContainingYourDevScript'
pipeline = load 'functions.groovy'
pipeline.dev()
}
2) Just call a second Jenkins job with this kind of line :
node() {
stage "UAT"
// Your existing UAT pipeline content here
build job: "dev-job"
}
With these 2 solutions you can configure your first job to run every minute and it will trigger the second part/job only if the first one finishes with success (otherwise Jenkins will just fail the build as it would normally do).
I have many Jenkins Jobs that I need to run on every Build,
At present time I have 4 slave servers.
I would like the jobs to run in parallel as much as possible, hence I defined the jobs as follow:
Execute concurrent builds if necessary - Disabled
Restrict where this project can be run - Enabled with the following values SalveLinux1HT||SalveLinux2HT||SalveLinux3HT||SalveLinux4HT
To my understanding if Job A and B are triggered at the same time, one should use 1HT and the other should use 2HT and they can run in parallel
however Jenkins build job A on all 4 slaves and only after it's finished he will build job B on all 4 slaves
This is the opposite of my goal
Any ideas?
Thanks in advance
You can use
Build Flow Plugin
You can find both installation and configuration instructions of this plugin at the above mentioned link.
If you want to run any jobs in parallel you can use following scripts:
parallel (
// job A and B will be scheduled in parallel.
{ build("jobA") },
{ build("jobB") }
)
// jobC will be triggered after jobs A and B are completed
build("jobC")
i have 2 pipelines in jenkins and i need to run a final job if last 2 jobs in 2 pipelines are successfull.
job 1 ( which will build periodically at 7PM ) will call 2 jobs job_pipeline1_1 and job_pipeline2_1.
job1
job_pipeline1_1 -- job_pipeline1_2
job_pipeline2_1 -- job_pipeline2_2
job_final (should be called only after job_pipeline1_2, job_pipeline2_2 are successfull)
job_pipeline1_1 and job_pipeline1_2 are independent of job_pipeline2_1 and job_pipeline2_2 and will run on differnt servers.
job_final should be called only if job_pipeline1_2 and job_pipeline2_2 are successfull in that particular build.
job_final should be in the pipeline.
check this image "http://i.stack.imgur.com/58Upc.png"
Can any one help me in this regard?
Thanks in advance.
You can use Jenkins plugin "Build Flow Plugin" to run your jobs in parallel.
In that case your final job will be executed after completion of parallel jobs.