Getting cause for branch indexing in multibranch pipeline

172 views
Skip to first unread message

Ramanathan Muthaiah

unread,
Aug 21, 2018, 1:01:57 PM8/21/18
to Jenkins Users
Am referring to this API doc to find out which method should be used to identify the reason for a build job to be triggered.


Would appreciate if anyone on this list could point me to the relevant method ?

For some strange reason, GHE org folder config (in prod Jenkins) does not have periodic triggering / scanning (that initiates branch indexing) but the detected repos have that option enabled !!!

--
regards
Ram

Sverre Moe

unread,
Aug 22, 2018, 4:59:01 AM8/22/18
to Jenkins Users


import jenkins.branch.BranchIndexingCause

   
final def jenkinsInstance = jenkins.model.Jenkins.getInstance()
    final def jenkinsProject = jenkinsInstance.getItemByFullName(jenkinsProjectName)
    if (jenkinsProject != null) {
        final def job = jenkinsProject.getAllJobs().first()
        final def lastBuild = job.getLastBuild()
        final def causes = previousBuild.getCauses()
        final def buildCause = causes.first()
        if (buildCause instanceof BranchIndexingCause) {

        }
    }

Ramanathan Muthaiah

unread,
Aug 23, 2018, 4:36:20 AM8/23/18
to Jenkins Users
Thanks Sverre Moe, you made my day !

Here is the final version of the code snippet. 
 
import jenkins.branch.BranchIndexingCause

   
final def jenkinsInstance = jenkins.model.Jenkins.getInstance()
    final def jenkinsProject = jenkinsInstance.getItemByFullName(jenkinsProjectName)
    if (jenkinsProject != null) {
        final def job = jenkinsProject.getAllJobs().first()
        final def lastBuild = job.getLastBuild()
        final def causes = lastBuild.getCauses()
        final def buildCause = causes.first()
        if (buildCause instanceof BranchIndexingCause) {

        }
    }

/Ram
Reply all
Reply to author
Forward
0 new messages