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:

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

相关推荐
大柏怎么被偷了8 分钟前
【Git】远程操作
git
studytosky1 小时前
Linux 基础开发工具(3):Git 控制与 GDB 调试实用指南
linux·运维·服务器·网络·数据库·git
云闲不收2 小时前
AI编程系列——git-worktree并行开发
git·ai编程
秦时明月天明2 小时前
GitLab SSH Key 过期:git pull failed : remote your ssh key has expired
git·ssh·gitlab
桃花岛主703 小时前
命令提交git到github上的步骤
git·github
AI逐月3 小时前
Git 停止追踪已提交文件问题
大数据·git·elasticsearch
是毛毛吧3 小时前
开发环境配置指南:解决 GitHub 连接超时与依赖下载失败的问题
网络·git·网络安全·docker·信息与通信
bj_zhb4 小时前
git stash 用法
git
rockmelodies4 小时前
本地 PyCharm 生成的 Git 仓库与 GitHub 远程仓库关联起来
git·pycharm·github
阿萨德528号5 小时前
Git 与 SVN 对比详解
git·svn