List Git Branches Parameter | Jenkins pluginAdds ability to choose from git repository revisions or tagshttps://plugins.jenkins.io/list-git-branches-parameter/

1、安装组件  List Git Branches


Jenkins List Git Branches插件 构建选择指定git分支_jenkins

2、验证功能


1)新建任务 

Jenkins List Git Branches插件 构建选择指定git分支_git_02

2)新增构建参数 

Jenkins List Git Branches插件 构建选择指定git分支_jenkins_03

3)选择git仓库
我这里选择gitee,其他类似。仓库如果不是公开的,需要配置key 

Jenkins List Git Branches插件 构建选择指定git分支_git仓库_04

4)jenkins配置git仓库

Jenkins List Git Branches插件 构建选择指定git分支_git_05

Jenkins List Git Branches插件 构建选择指定git分支_jenkins_06

5)开始构建
点击【build with praameters】,可以选择git分支版本了

Jenkins List Git Branches插件 构建选择指定git分支_List_07

6)优化git分支名称
选择【配置】—>【高级】,在【branch filter】添加“refs/heads/(.*)”,点击保存

Jenkins List Git Branches插件 构建选择指定git分支_List_08

选择【build with parameters】分支名称更简洁了

Jenkins List Git Branches插件 构建选择指定git分支_List_09

注意这里是"${env.BRANCH}"而不是单引号!!

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']]])                   
                }
            }
        }
    }
}