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:

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

相关推荐
wordbaby7 小时前
公私分明:为什么你不应该共用 SSH Key(附多账号最佳实践指南)
前端·git·ssh
Albert Edison8 小时前
【Git】分支管理
大数据·git·elasticsearch
Forest_HAHA9 小时前
<4>,Git多人协作
git
CNRio11 小时前
Day 43:Git的高级技巧:使用Git的rebase简化提交历史
大数据·git·elasticsearch
少云清11 小时前
【接口测试】2_持续集成 _Git与Gitee
git·ci/cd·gitee
Star_KeyW11 小时前
【超详细】Git基础命令使用
git
Forest_HAHA12 小时前
<1>,Git基本操作
git
Forest_HAHA13 小时前
<2>,Git分支管理
git
最贪吃的虎14 小时前
深入理解Git Commit的工作原理:从对象引用到空间优化
java·前端·git·后端·spring·开源
Forest_HAHA14 小时前
<3>,Git远程操作
git