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
を設定をチェックするパイプラインスクリプトからの抜粋です。 echo {$pom.version}
は1.1.0-RELEASE
と表示されます。これは、マスターブランチの正しいリリースです。しかし私は実際にビルドしようとしているTestBranch
ブランチのために1.1.1-SNAPSHOT
を予期しています。 ログは、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上にすべてのリポジトリを設定すると、あいまいさが発生する可能性があります。私はパイプラインスクリプトを通してこれを達成する必要があります。
ありがとうございました!