“定期构建"詹金斯的多分支流水线

问题描述:

我正在使用Pipeline插件运行Jenkins 2.我已经建立了一个多分支管道项目,其中每个分支(主分支,开发分支等)在根目录中都有一个Jenkinsfile.设置起来很简单.但是,即使代码未更改,如何使每个分支定期运行(而不是分支索引),我还是一头雾水.我需要在我的Jenkins文件中添加什么以启用定期构建?

I'm running Jenkins 2 with the Pipeline plugin. I have setup a Multi-branch Pipeline project where each branch (master, develop, etc.) has a Jenkinsfile in the root. Setting this up was simple. However, I'm at a loss for how to have each branch run periodically (not the branch indexing), even when the code does not change. What do I need to put in my Jenkinsfile to enable periodic builds?

如果使用声明性样式的Jenkinsfile,则使用

If you are using a declarative style Jenkinsfile then you use the triggers directive.

pipeline {
    agent any
    triggers {
        cron('H 4/* 0 0 1-5')
    }
    stages {
        stage('Example') {
            steps {
                echo 'Hello World'
            }
        }
    }
}