Skip to content

Commit

Permalink
add nextVersion tag in git for multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
smerleCB committed Aug 4, 2023
1 parent b04051d commit 8762547
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion vars/buildDockerAndPublishImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def call(String imageShortName, Map userConfig=[:]) {
final Date now = new Date()
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
final String buildDate = dateFormat.format(now)
String nextVersion = '' //global
boolean flagmultiplatforms = false
if (finalConfig.platforms.size() > 0) {
echo "INFO: Using platforms from the pipeline configuration"
Expand Down Expand Up @@ -84,7 +85,7 @@ def call(String imageShortName, Map userConfig=[:]) {
"IMAGE_PLATFORM=${oneplatform}",
]) {
infra.withDockerPullCredentials{
String nextVersion = ''
nextVersion = '' // reset for each turn
stage("Prepare ${imageName}") {
checkout scm
if (finalConfig.unstash != '') {
Expand Down Expand Up @@ -304,6 +305,41 @@ def call(String imageShortName, Map userConfig=[:]) {
} // each platform
if (flagmultiplatforms) {
node(finalConfig.agentLabels) {
stage("Multiplatform Semantic Release of ${defaultImageName}") {
echo "Configuring credential.helper"
// The credential.helper will execute everything after the '!', here echoing the username, the password and an empty line to be passed to git as credentials when git needs it.
if (isUnix()) {
sh 'git config --local credential.helper "!set -u; echo username=\\$GIT_USERNAME && echo password=\\$GIT_PASSWORD && echo"'
} else {
// Using 'bat' here instead of 'powershell' to avoid variable interpolation problem with $
bat 'git config --local credential.helper "!sh.exe -c \'set -u; echo username=$GIT_USERNAME && echo password=$GIT_PASSWORD && echo"\''
}

withCredentials([
usernamePassword(credentialsId: "${finalConfig.gitCredentials}", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')
]) {
withEnv(["NEXT_VERSION=${nextVersion}"]) {
echo "Tagging and pushing the new version: ${nextVersion}"
if (isUnix()) {
sh '''
git config user.name "${GIT_USERNAME}"
git config user.email "jenkins-infra@googlegroups.com"
git tag -a "${NEXT_VERSION}" -m "${IMAGE_NAME}"
git push origin --tags
'''
} else {
powershell '''
git config user.email "jenkins-infra@googlegroups.com"
git config user.password $env:GIT_PASSWORD
git tag -a "$env:NEXT_VERSION" -m "$env:IMAGE_NAME"
git push origin --tags
'''
}
} // withEnv
} // withCredentials
} // stage
stage('Multiplatforms Amend') {
infra.withDockerPushCredentials {
if (env.TAG_NAME || env.BRANCH_IS_PRIMARY) {
Expand Down

0 comments on commit 8762547

Please sign in to comment.