【jenkins】参数化构建git分支

1. 使用字符串参数构建

 

 

2. 配置pipeline

        stage('Checkout') {
            steps {
                script{
branch = branch
if (env.gitlabSourceBranch != null) { checkout changelog: true, poll: true, scm: [ $class: 'GitSCM', branches: [[name: "origin/${env.gitlabSourceBranch}"]], doGenerateSubmoduleConfigurations: false, extensions: [[ $class: 'PreBuildMerge', options: [ fastForwardMode: 'FF', mergeRemote: 'origin', mergeStrategy: 'default', mergeTarget: "${env.gitlabTargetBranch}" ] ]], extensions: [[ $class: 'UserIdentity', email: "${env.gitlabUserEmail}", name: "${env.gitlabUserName}" ]], extensions: [[ $class: 'RelativeTargetDirectory', relativeTargetDir: 'project_name' ]], submoduleCfg: [], userRemoteConfigs: [[ url: "${env.gitlabSourceRepoURL}" ]] ] } else { checkout([$class: 'GitSCM', branches: [[name: 'origin/${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: true, parentCredentials: false, recursiveSubmodules: false, reference: '', trackingSubmodules: false], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'project_name']], submoduleCfg: [], userRemoteConfigs: [[url: 'xxxxxxxx']]]) } } } }

3. 其他方法

安装插件Git Parameter

 

参考链接:

https://www.cnblogs.com/gexiaoshan/p/10145312.html

posted @ 2022-02-28 20:35  代码诠释的世界  阅读(779)  评论(0编辑  收藏  举报