我在Jenkins有一个参数化(声明)管道。该脚本应该构建作为参数传递的分支,但始终以构建主分支结束。Jenkins参数化管道总是建立主分支
这是从流水线脚本在指定的分支
pipeline {
agent any
tools {
maven "localMaven"
git "Default"
}
parameters {
string(defaultValue: 'develop', description: 'Commit/Branch', name: 'prop1')
}
stages {
stage('Pom-Version') {
steps{
echo "prop1 $prop1"
checkout([$class: 'GitSCM',
userRemoteConfigs: [[url: 'https://github.com/path/to/repo',
credentialsId: 'xxx',
branches: [name: "${params.prop1}"]]]
])
script {
pom = readMavenPom file: 'pom.xml'
modelversion = pom.version.substring(0, pom.version.lastIndexOf("-"))
}
sh "echo {$pom.version}"
sh "echo {$modelversion}"
}
}
.....
我设置的参数prop1=refs/heads/TestBranch
建设回购后检查POM版本的片段。 echo {$pom.version}
显示1.1.0-RELEASE
。这是主分支的正确版本。但我正在为1.1.1-SNAPSHOT
预测我正在尝试构建的分支TestBranch
。 日志确认它正在构建主分支而不是TestBranch。查找行:在下面的日志
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/https://github.com/path/to/repo # timeout=10
Fetching upstream changes from https://github.com/https://github.com/path/to/repo
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://github.com/https://github.com/path/to/repo +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 9832b614717ebf86f93d983342787b717dcfb4d9 (refs/remotes/origin/master)
Commit message: "Merge branch 'release/1.1.0-RELEASE'"
> git config core.sparsecheckout # timeout=10
> git checkout -f 9832b614717ebf86f93d983342787b717dcfb4d9
> git rev-list 9832b614717ebf86f93d983342787b717dcfb4d9 # timeout=10
refs/remotes/origin/origin/master^{commit}
应该说refs/remotes/origin/origin/TestBranch^{commit}
左右。
我知道,在管道配置jenkins UI我可以设置要建立的分支。但是这已经被设置到repo +分支,其中管道脚本应该被从中拉出。当我在UI上配置所有回购站时,可能会出现歧义。我需要通过管道脚本实现这一点。
感谢您的帮助!