How can a build pipeline be scheduled to execute at a certain time of the night just like a regular job can be?
As soon as we will hit the URL in the browser, Jenkins will trigger the build automatically like in the below image.
The steps for schedule jobs in Jenkins:click on "Configure" of the job requirement. scroll down to "Build Triggers" - subtitle. Click on the checkBox of Build periodically. Add time schedule in the Schedule field, for example: @midnight.
Declarative pipeline has triggers
directive, one uses it like this:
triggers { cron('H 4/* 0 0 1-5') }
I took it from Pipeline Syntax docs
You can set the job parameters using the following syntax:
properties([pipelineTriggers([cron('H 23 * * *')])])
Adding this line to your build script or Jenkinsfile will configure the job to run every night at 11PM.
Complete Example (taken from docs) Ref: https://jenkins.io/doc/book/pipeline/syntax/#triggers
pipeline {
agent any
triggers {
cron('H */4 * * 1-5')
}
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With