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:

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

相关推荐
轮到我狗叫了21 小时前
git - 版本控制工具 - 对应的常见命令 - 以及无需后续每次手动source conda
git
changxiang1 天前
GIT 备忘
git
DogDaoDao1 天前
Windows 开发提效工具全景指南:60+ 工具的工程化分层配置
windows·git·程序员·开发工具·powershell·everything·msys2
wdfk_prog2 天前
GitHub push 失败:如何扫描并清理 Git 历史中的大文件
git·elasticsearch·github
大明二代2 天前
使用 Traefik、cert-manager 和 DNS-01 为内网 Kubernetes 服务配置 HTTPS
git·kubernetes·flux
小芒果_012 天前
git常用命令速查
大数据·git·elasticsearch
2501_930472442 天前
腾讯云助手规范化Git提交记录
git·elasticsearch·腾讯云
风尘小子2 天前
git的.gitignore文件中文件和目录配置
git
Tanner_SL3 天前
Linux笔记之GIT常用命令
linux·git
醉颜凉3 天前
Jenkins与Git集成完全指南:从基础配置到自动触发构建
运维·git·jenkins