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

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


2、验证功能


1)新建任务

2)新增构建参数

3)选择git仓库

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

4)jenkins配置git仓库

5)开始构建

点击【build with praameters】,可以选择git分支版本了

6)优化git分支名称

选择【配置】--->【高级】,在【branch filter】添加"refs/heads/(.*)",点击保存

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

最后拿到分支了就是去拉取指定分支的代码了,注意这里是"${env.BRANCH}"而不是单引号!!

java 复制代码
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']]])                   
                }
            }
        }
    }
}
相关推荐
007张三丰1 天前
软件测试专栏(15/20):REST Assured接口自动化框架实战
运维·自动化·jenkins·接口自动化·rest·assured
qq_452396233 天前
第二篇:《Jenkins 从零搭建:安装、配置与第一个 Pipeline》
java·运维·jenkins
用户6757049885023 天前
手摸手教你玩 Jenkins,一次搞懂 CI/CD!(第三章:发布之nodeAgent)
后端·jenkins
qq_452396233 天前
第三篇:《Jenkins Pipeline as Code:Declarative Pipeline 深度实战》
java·servlet·jenkins
用户6757049885024 天前
手摸手教你玩 Jenkins,一次搞懂 CI/CD!(第二章:发布之sshPublisher)
后端·jenkins
用户6757049885024 天前
手摸手教你玩 Jenkins,一次搞懂 CI/CD!(第一章:部署)
后端·jenkins
行者-全栈开发4 天前
Jenkins 与 GitLab 深度集成实战:从 Webhook 到 Merge Request 全流程自动化
gitlab·jenkins·webhook·merge request·multibranch·source plugin·ci/cd 自动化
2301_780303907 天前
DevSecOps建设之自动化集成与部署 Jenkins教程和使用案例
运维·自动化·jenkins
longze_713 天前
Github仓库一直拉取不了
github·jenkins
醉颜凉1 个月前
Elasticsearch高性能优化:Bulk API大规模数据导入性能调优全攻略
elasticsearch·性能优化·jenkins