Skip to content

Commit

Permalink
fail in case git add or git commit fails during artifactSetVersion (#…
Browse files Browse the repository at this point in the history
…1491)

* fail in case git add or git commit fails during artifactSetVersion

* check if there is a git config on os level

* better error message in case no user name/mail are configured


Co-authored-by: Srinikitha Kondreddy <[email protected]>

Co-authored-by: Srinikitha Kondreddy <[email protected]>
  • Loading branch information
marcusholl and srinikitha09 authored May 11, 2020
1 parent 37a6d45 commit 803071f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions vars/artifactSetVersion.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,29 @@ void call(Map parameters = [:], Closure body = null) {

def gitConfig = []

if(config.gitUserEMail) gitConfig.add("-c user.email=\"${config.gitUserEMail}\"")
if(config.gitUserName) gitConfig.add("-c user.name=\"${config.gitUserName}\"")
if(config.gitUserEMail) {
gitConfig.add("-c user.email=\"${config.gitUserEMail}\"")
} else {
// in case there is no user.email configured on project level we might still
// be able to work in case there is a configuration available on plain git level.
if(sh(returnStatus: true, script: 'git config user.email') != 0) {
error 'No git user.email configured. Neither via project config nor on plain git level.'
}
}
if(config.gitUserName) {
gitConfig.add("-c user.name=\"${config.gitUserName}\"")
} else {
// in case there is no user.name configured on project level we might still
// be able to work in case there is a configuration available on plain git level.
if (sh(returnStatus: true, script: 'git config user.name') != 0) {
error 'No git user.name configured. Neither via project config nor on plain git level.'
}
}
gitConfig = gitConfig.join(' ')

try {
sh """#!/bin/bash
set -e
git add . --update
git ${gitConfig} commit -m 'update version ${newVersion}'
git tag ${config.tagPrefix}${newVersion}"""
Expand Down

0 comments on commit 803071f

Please sign in to comment.