SCM Poll in jenkins multibranch pipeline
Asked Answered
C

1

-2

Wanted to accommodate scheduled build starting 12AM every 3 hrs till 3PM on every weekday(mon-fri). It should be triggered build only if anything is committed into github repository.

Please provide the exact code as few code is working for multi-branch but not for above schedule.

Condemnatory answered 20/11, 2018 at 8:29 Comment(0)
D
1

Sorry what do you mean by the scheduled "build"?

  1. Do you want the Multi-Branch to check for more branches on your given interval?

If so you can only do it by "Scan Multibranch Pipeline with defaults Triggers"

  1. Do you want to issue a build on the branch when there is change on it?

Noted that the option in

the mult-branch folder > "Scan Multibranch Pipeline with defaults Now" and get all current branches > status > the jobs > View Configuration

is read only.

So, to alter the option, from https://issues.jenkins-ci.org/browse/JENKINS-33900?focusedCommentId=326181&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-326181 , I think you should use the Jenkinsfile to do theSCM for every job.

So, for all jobs you need to configure for SCM poll, include a Jenkinsfile on Git for each of them (Don't forget to install the pipeline-model-definition plugin and all its dependent plugins):

pipeline {
  triggers {
        pollSCM('H 0-15/3 * * H(1-5)')
           }
    agent any
    stages{
        stage('Build') {
            steps {
            echo 'Building.. or whatever'
            }
        }
    }

}

That should do the job, at least it works for me``

Hope it helps

Defrayal answered 20/11, 2018 at 10:7 Comment(5)
We have used the same structure. Its working in normal pipeline job. But not working with multibranch pipiline jobsCondemnatory
Sorry that I thought multi-branch has that option too. I am working on itDefrayal
Answer Edited, please checkDefrayal
Please mark this answer the best if it successfully solves your problem or tell me if it does not workDefrayal
Please accept the answer if it helps you or it is a correct answer. Or you may tell me if it does not workDefrayal

© 2022 - 2024 — McMap. All rights reserved.