简体   繁体   中英

Jenkins pipeline multi trigger options on Git branch

My requirement is to trigger CI/CD pipeline as soon as a release branch is created, commit and merge is made to release branch. The name of my release branch will vary from release to release such as release/v1. 0, release/v1. 1 or release/v2.0 release/v1. 0, release/v1. 1 or release/v2.0 release/v1. 0, release/v1. 1 or release/v2.0 etc.

Due to security aspects we are not allowed to use web hooks for git trigger options, instead we use SCM poll (every minute) option of Jenkins to trigger pipeline.

The issue we are facing here is below snippet of Jenkins pipeline fails to point to release/v1.0 for git checkout. Our pipeline should trigger whenever a release branch is created or merged or commit happens.

stage ('Git Checkout')
{
    git(url: "${GIT_URL}",credentialsId: "${GIT_CREDENTIALS_ID}",branch: 'release/*')       
}

This can be fixed by using below Git Stage in Jenkins pipeline.

    stage ('GIT CHECKOUT')
    {
        checkout poll:true, scm: ([$class: 'GitSCM',
        branches: [[name: 'origin/release/*']],
        userRemoteConfigs: [[credentialsId: "${GIT_CREDENTIALS_ID}", url: "${GIT_URL}"]]
        ])
        
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM