pipeline 使用git parameter插件实现动态选择分支构造

效果,,点击build with Parameters 就会出现右边的当前仓库的所有的分支,默认最多显示5个,可以修改配置,修改显示的最大分支数量。

  1. 安装git params插件

  2. 搜索git parameter 插件 ,我这里是已经安装成功的

  3. 使用pipeline构建时动态获取分支名
    在pipeline script里面添加获取分支的脚本:

    pipeline {
    agent any
    // 参数配置,只有在里配置了,git parameter插件才会生效
    parameters {
    gitParameter(
    branchFilter: 'origin/(.*)',
    defaultValue: 'main',
    name: 'BRANCH',
    type: 'PT_BRANCH',
    // 需要拉取分支的仓库
    useRepository: 'http://124.71.140.30:7070/xinyue/student-video-course.git'
    )
    }

    复制代码
     stages {
         stage('Build') {
             steps {
                 checkout scmGit(branches: [[name: '${BRANCH}']], extensions: [], userRemoteConfigs: [[credentialsId: '8be22b7b-709e-4f7e-93c4-c996e6fe250d', url: 'http://124.71.140.30:7070/xinyue/student-video-course.git']])               
             }
         }
     }

    }

上面脚本中,credentialsId是访问git仓库的凭证id,可以在jenkins的凭证管理中添加凭证,会生成一个唯一的id:

点击全局,进入到凭证列表,右上角可以添加新的凭证

相关推荐
解道Jdon2 分钟前
[Budi插件:VsCode状态栏显示Copilot使用情况
ide·windows·git·svn·eclipse·github·visual studio
kisshyshy8 分钟前
掌握 Git 基础
git
全糖可乐气泡水44 分钟前
Codex适配国产信创环境安装部署与技术适配全解析
开发语言·git·python·算法·百度
一只大袋鼠3 小时前
Git 四种仓库连接方式操作指南
git
活宝小娜6 小时前
git windows安装教程
git
青春喂了后端8 小时前
Go Sidecar Repository 并发锁改造:让并发请求安全地进入 Git 仓库层
git·安全·golang
小雨青年8 小时前
GitHub Actions 工作流性能优化实战,先看瓶颈,再改缓存和并发
git
0x000710 小时前
Git Bash 中无法启动 Claude Code ?
开发语言·git·bash
xuhaoyu_cpp_java10 小时前
Git学习(六)
git·学习
happyness441 天前
Git:AI编程时代的“安全带“与“时光机“
git·ai编程