“Build Periodically” with a Multi-branch Pipeline in Jenkins

后端 未结 5 753
南旧
南旧 2020-11-30 20:29

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. Settin

相关标签:
5条回答
  • 2020-11-30 20:35

    I was able to find an example illustrating this an discarding old builds, which is also something I wanted.

    Jenkinsfile in jenkins-infra/jenkins.io:

    properties(
        [
            [
                $class: 'BuildDiscarderProperty',
                strategy: [$class: 'LogRotator', numToKeepStr: '10']
            ],
            pipelineTriggers([cron('H/30 * * * *')]),
        ]
    )
    
    0 讨论(0)
  • 2020-11-30 20:44

    This is working for me:

      triggers {
        cron(env.BRANCH_NAME == 'development' ? 'H */12 * * *' : '')
      }
    

    See more in this article

    0 讨论(0)
  • 2020-11-30 20:44

    For Paramertized periodic runs or scheduled triggers, one could use as follows.

    triggers{
        parameterizedCron env.BRANCH_NAME == "develop" ? '''H 03 * * * % buildSlave=vm1;testSlave=vm2;HYPERVISOR=vbox;VERSION=10.5.0.0
    H 03 * * * % buildSlave=vm1;testSlave=vm2;HYPERVISOR=workstation;VERSION=10.5.0.0''' : ""
    }
    
    0 讨论(0)
  • 2020-11-30 20:53

    If you use a declarative style Pipeline and only want to trigger the build on a specific branch you can do something like this:

    String cron_string = BRANCH_NAME == "master" ? "@hourly" : ""
    
    pipeline {
      agent none
      triggers { cron(cron_string) }
      stages {
        // do something
      }
    }
    

    Found on Jenkins Jira

    0 讨论(0)
  • 2020-11-30 20:57

    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'
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题