1. Install the component List Git Branches
2. Verification function
1) Create a new task
2) Added new build parameters
3) Select the git repository.
I choose gitee here, and the others are similar. If the warehouse is not public, you need to configure the key
4) jenkins configures git warehouse
5) Start building.
Click [build with praameters] to select the git branch version.
6) Optimize the git branch name
. Select [Configuration] -> [Advanced], add "refs/heads/(.*)" in [branch filter], and click Save
Select [build with parameters] to make the branch name more concise.
Finally, after getting the branch, it is time to pull the code of the specified branch. Note that it is "${env.BRANCH}" instead of single quotes! !
pipeline {
agent any
stages {
stage('Hello') {
steps {
script{
print(env.BRANCH)
checkout([$class: 'GitSCM', branches: [[name: "${env.BRANCH}"]], extensions: [], userRemoteConfigs: [[credentialsId: '33375fd1-0418-4b7a-a65e-4ffcebd8e7da', url: 'http://192.168.11.129/root/devops-maven-service.git']]])
}
}
}
}
}