运维知识库-BigHead
  • 首页
  • 电子书-知识库老版本
  • VIP视频免费看
  • 联系作者
  • 随笔
https://github.com/yongxiaodong
  1. 首页
  2. Jenkins
  3. 正文

Jenkins pipeline添加自动获取分支案例

2021年02月26日 3984点热度 3人点赞 0条评论

在jenkins构建时,自动从git获取所有的分支名,并显示出来供用户选择过滤

效果图:

pipeline代码示例

pipeline {
    agent any

    options {
      buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '15', numToKeepStr: '15')
    }
     parameters {
            string defaultValue: 'https://gitlab.haojiequ.com/dtkgo/dtk_go_app_api.git', description: '项目的git地址', name: 'GIT_PROJECT_URL', trim: false
            choice choices: ['test1', 'test2', 'test3', 'huise', 'dev1'], description: '选择发布环境,默认发布至test1测试环境', name: 'PENV'    
            gitParameter name: 'GIT_BRANCH', 
                         type: 'PT_BRANCH_TAG',
                         branchFilter: 'origin/(.*)',
                         defaultValue: 'master',
                         selectedValue: 'DEFAULT',
                         sortMode: 'DESCENDING_SMART',
                         quickFilterEnabled: true, 
                         description: 'Select your branch or tag.'

        }

    stages {
        stage('初始化'){
            steps {
                script {
                   env.rootdir = '/home/yxd/'
                   env.appname = 'dtkAppApi'

                }
            }
        }
        stage('Hello') {
            steps {
                checkout([class: 'GitSCM', branches: [[name: "{GIT_BRANCH}"]], extensions: [[class: 'CheckoutOption', timeout: 20], [class: 'CloneOption', depth: 1]], userRemoteConfigs: [[credentialsId: "5ee2cb96-43d2-47e3-9a8a-6d6ee00b9f09", url: "${GIT_PROJECT_URL}"]]])
            }
        }
        stage('Build') {
            steps {
                sh 'source ~/.bashrc   && go build'
            }
        }
    }
}

标签: 暂无
最后更新:2021年03月09日

BigHead

保持饥渴的专注,追求最佳的品质

点赞
< 上一篇

文章评论

取消回复
文章归档
  • 2022年7月
  • 2021年6月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2020年8月
  • 2020年7月
分类目录
  • ELK
  • Jenkins
  • K8S
  • Nginx
  • Openvpn
  • Python
  • 小技能
  • 未分类

COPYRIGHT © 2020 运维知识库-BigHead. ALL RIGHTS RESERVED.

蜀ICP备16012425号