Jenkins Pipeline:使用Git Parameter Plugin 实现参数化构建时选择分支和Tag

Plugin:Git parameter

Important:

If you need use other type (other then branch) parameter, you must use git within checkout

Important settings:

  • It should be set a default value because initial build must get this information
  • Using git should be set a branchFilter as ‘origin/(.*)’ (origin is a Remote Server name)

Jenkins Pipeline:

/**
*Use Git parameter plugin to Adds ability to choose branches, 
*tags or revisions from git repository configured in project.
*/

pipeline {
    agent any
    parameters {
        gitParameter name: 'BRANCH_TAG', 
                     type: 'PT_BRANCH_TAG',
                     branchFilter: 'origin/(.*)',
                     defaultValue: 'master',
                     selectedValue: 'DEFAULT',
                     sortMode: 'ASCENDING_SMART',
					 description: 'Select your branch or tag.'
    }
    stages {
        stage('Example') {
            steps {
                checkout([$class: 'GitSCM', 
                          branches: [[name: "${params.BRANCH_TAG}"]], 
                          doGenerateSubmoduleConfigurations: false, 
                          extensions: [], 
                          gitTool: 'Default', 
                          submoduleCfg: [], 
                          userRemoteConfigs: [[url: 'https:/192.168.1.2/scm/test.git',credentialsId: 'for_gitlab',]]
                        ])
            }
        }
    }
}

相关文章

本篇内容主要讲解“gitee如何上传代码”,感兴趣的朋友不妨来...
这篇“从gitee上下的代码如何用”文章的知识点大部分人都不太...
这篇文章主要介绍“gitee如何下载仓库里的项目”,在日常操作...
本篇内容主要讲解“怎么在Gitee上更新代码”,感兴趣的朋友不...
本文小编为大家详细介绍“怎么将工程托管到gitee”,内容详细...
这篇文章主要介绍了gitee中图片大小如何调整的相关知识,内容...