0


Jenkins List Git Branches插件 构建选择指定git分支

List Git Branches Parameter | Jenkins pluginAdds ability to choose from git repository revisions or tagshttps://plugins.jenkins.io/list-git-branches-parameter/

1、安装组件 List Git Branches


2、验证功能


**1)新建任务 **

**2)新增构建参数 **

3)选择git仓库
我这里选择gitee,其他类似。仓库如果不是公开的,需要配置key

4)jenkins配置git仓库

5)开始构建
点击【build with praameters】,可以选择git分支版本了

6)优化git分支名称
选择【配置】—>【高级】,在【branch filter】添加“refs/heads/(.*)”,点击保存

选择【build with parameters】分支名称更简洁了

最后拿到分支了就是去拉取指定分支的代码了,注意这里是"${env.BRANCH}"而不是单引号!!

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                script{
                    print(env.BRANCH)
                    checkout([$class: 'GitSCM', branches: [[name: "${env.BRANCH}"]], extensions: [], userRemoteConfigs: [[credentialsId: '33375fd1-0418-4b7a-a65e-4ffcebd8e7da', url: 'http://192.168.11.129/root/devops-maven-service.git']]])                   
                }
            }
        }
    }
}
标签: jenkins

本文转载自: https://blog.csdn.net/qq_34556414/article/details/132826533
版权归原作者 富士康质检员张全蛋 所有, 如有侵权,请联系我们删除。

“Jenkins List Git Branches插件 构建选择指定git分支”的评论:

还没有评论