Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Build Pipeline Scheduled Trigger

Tags:

jenkins

How can a build pipeline be scheduled to execute at a certain time of the night just like a regular job can be?

like image 305
user1934783 Avatar asked Aug 15 '15 19:08

user1934783


People also ask

Can Jenkins build be triggered automatically?

As soon as we will hit the URL in the browser, Jenkins will trigger the build automatically like in the below image.

How do you trigger a periodically in Jenkins?

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.


3 Answers

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

like image 96
BartBiczBoży Avatar answered Oct 19 '22 03:10

BartBiczBoży


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.

like image 34
Joshua Bussdieker Avatar answered Oct 19 '22 05:10

Joshua Bussdieker


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'
            }
        }
    }
}
like image 25
Satish Gadhave Avatar answered Oct 19 '22 04:10

Satish Gadhave