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:

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

相关推荐
德彪稳坐倒骑驴1 天前
Git常用命令
git
无限进步_1 天前
【C语言&数据结构】对称二叉树:镜像世界的递归探索
c语言·开发语言·数据结构·c++·git·算法·visual studio
qq_5470261791 天前
Git 使用指南
git
XiaoHu02071 天前
Linux多线程(详细全解)
linux·运维·服务器·开发语言·c++·git
*才华有限公司*1 天前
RTSP视频流播放系统
java·git·websocket·网络协议·信息与通信
juelianhuayao1 天前
Git错误提交后如何快速删除本次commit
git
chen<>1 天前
Git原理与应用
大数据·git·elasticsearch·svn
小兔崽子去哪了1 天前
Git 专题
git
金米kk1 天前
git pull时报错Your local changes to the following files would…的解决办法
git
超级罗伯特1 天前
git一次性完成仓库下载及所有分支获取
git·git仓库拉取