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:

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

相关推荐
Data_Adventure9 小时前
能连上 GitHub(SSH 验证成功),却 push 失败?常见原因与逐步解决方案
前端·git·github
间彧10 小时前
如何解决Git客户端下载缓慢问题
git
Tearstornbyrain13 小时前
在Ubuntu24.04中使用ssh连接本地git仓库到github远程仓库
linux·git·ubuntu·ssh·github
四七伵16 小时前
一次 Git Rebase 事故,让我彻底明白 Rebase 和 Merge 的区别
git·后端
霖001 天前
FPGA的PS基础1
数据结构·人工智能·windows·git·算法·fpga开发
盗骊1 天前
Git rebase
git
芝麻馅汤圆儿1 天前
Git Bash
git
六件套是我2 天前
在idea中git切换分支,但是我的文件没add,没commit
git
Pi_Qiu_2 天前
Rsync自动化备份平台建设实战
git·自动化·github
parade岁月2 天前
Git黑科技:让你的配置文件"隐身",再也不用担心误提交!
git