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:

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

相关推荐
C++ 老炮儿的技术栈5 小时前
不调用C++/C的字符串库函数,编写函数strcpy
c语言·开发语言·c++·windows·git·postman·visual studio
清风~徐~来6 小时前
【Git】远程操作
git
阿凡达蘑菇灯11 小时前
git安装--gitlab操作
git·gitlab
Mo_YuO.o12 小时前
工作区 暂存区 版本库
git·gitee·github
深念Y12 小时前
本地Git仓库推送到Gitee教程
git·gitee·github·仓库·项目·源代码管理·初始化
白云千载尽12 小时前
a800上gazebo无法使用gpu的问题修复
网络·git·github
凯酱16 小时前
git 拉取指定分支
git
Easonmax17 小时前
【鸿蒙pc命令行适配】tig(git命令行可视化)工具移植实战:解决ncurses库依赖、terminfo终端适配与环境配置全流程
git·华为·harmonyos
petunsecn18 小时前
多 GitHub 账号与多平台 Git 使用(附加场景:就想用指定账号clone)
git·github
yuanmenghao19 小时前
Git submodule 与 git-repo(Google 的 repo 工具) 在多仓库管理上的差异
git