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++ 老炮儿的技术栈4 小时前
在C++ 程序中调用被 C编译器编译后的函数,为什么要加 extern “C”声明?
c语言·c++·windows·git·vscode·visual studio
Robin罗兵7 小时前
git使用教程2
git
bob_young9 小时前
Git LFS + Gerrit 配置+lfs-test-server(git lfs push总是提示输入https密码解决)
git·lfs
半夏微凉半夏殇12 小时前
git add . 是否会包含.o、.so、.ko文件?深度解析与避坑指南
git
牟同學13 小时前
Git 实战场景操作大全(可直接落地)
git
不做无法实现的梦~13 小时前
使用ros2跑mid360的fastlio2建图
git·单片机·嵌入式硬件·gitcode
长沙红胖子Qt15 小时前
SVN培训笔记(二):使用sourceTree通过git桥接管理svn项目
git·svn·sourcetree·sourcetree管理svn
半夏微凉半夏殇17 小时前
从多仓库到单仓库:如何高效迁移并统一管理多个Git项目
git
__万波__17 小时前
解决警告“..LF will be replaced by CRLF the next time Git touches it“
git
Software攻城狮18 小时前
git报错处理
git