[英]Jenkins Parameterized pipeline always builds master branch
我在詹金斯(Jenkins)中有一个参数化(声明性)管道。 该脚本应该构建作为参数传递的分支,但始终最终构建master分支。
这是管道脚本的片段,该脚本在指定分支上构建存储库后检查pom版本
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
。 echo {$pom.version}
显示1.1.0-RELEASE
。 这是master分支的正确版本。 但是我期望为我实际上试图构建的分支TestBranch
分配1.1.1-SNAPSHOT
。 日志确认它正在构建master分支而不是TestBranch。 在以下日志中查找以下行: refs/remotes/origin/origin/master^{commit}
> 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/TestBranch^{commit}
左右。
我知道在管道配置的jenkins UI上,我可以设置要构建的分支。 但这已经设置到应该从中提取管道脚本的repo +分支。 当我在UI上配置所有存储库时,可能会出现歧义。 我需要通过管道脚本来实现。
谢谢您的帮助!
我认为您在checkout
步骤中在错误的位置指定了分支,因为userRemoteConfigs类没有branches
字段。 应该是这样的:
checkout([$class: 'GitSCM',
branches: [[name: "${params.prop1}"]],
userRemoteConfigs: [[url: 'https://github.com/path/to/repo',
credentialsId: 'xxx']]
])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.