简体   繁体   中英

Jenkins pipeline - git branch

I am writing pipeline script in order to implement continuous integration flow in our project. The process is for users to do work in a specific branch that follows naming convention, test_id1 , test_id2 etc. Once these are pushed to remote repo, Jenkins kicks-in, it checks out branch with test* and does rest of the build process.

Based on my initial instinct, I wrote the pipeline script as follows: stage 'build'

node {
    git url: 'git@hd1:testing', branch: test*
    sh "pwd"
    sh "cat simple.csh"
    sh "echo $PATH"
    sh "csh simple.csh"
    echo("end of pipeline")
}

Btw, I have tried "test*", 'test*'.

Jenkins bails out with the following error:

Caused by: hudson.plugins.git.GitException: Command "git checkout -b test* 264dc398372cba41c026568bd764d2656ebfc511" returned status code 128:

So, the question is whether I am going in the right direction with this. I also looked at the error above and obviously, git checkout with a wildcard is something that would not serve the purpose. So, would the following approach work:

1) Checkout git master as usual 2) Check if any new branch by the name test* exists 3) If it does, checkout the branch and then do rest of the build

Need some directions on this ...

You can use SCM checkout plugin with regular expression. I've used to poll the feature branches with the format feature/US1234. Modify like you need.

checkout([$class: 'GitSCM', 
branches: [[name: ':^(?i)origin/feature/[a-z|A-Z]{2}[0-9].*']], 
doGenerateSubmoduleConfigurations: false, 
extensions: [[$class: 'WipeWorkspace'], 
[$class: 'LocalBranch', localBranch: '**']], submoduleCfg: [], 
userRemoteConfigs: [[credentialsId: 'YOURID', url: 'GITURL']]]) 

Use pipeline syntax generator for more option.

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