1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

Do only what is really needed inside the body of sshAgent

- there is no need to do the git commit inside the body of sshAgent
- there is no need to do the git tag inside the body of sshAgent

- side catch: availablility of git user name and git user email is
  checked at its own. If one is missing the other may be present
  ~somehow~ in the configuration.
This commit is contained in:
Marcus Holl 2018-09-03 13:39:59 +02:00
parent c93c1079cc
commit 12d8f48c38
2 changed files with 18 additions and 15 deletions

View File

@ -76,8 +76,8 @@ class ArtifactSetVersionTest extends BasePiperTest {
assertThat(jscr.shell, hasItem("mvn --file 'pom.xml' --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn versions:set -DnewVersion=1.2.3-20180101010203_testCommitId -DgenerateBackupPoms=false"))
assertThat(jscr.shell, hasItem('git add .'))
assertThat(jscr.shell, hasItem("git commit -m 'update version 1.2.3-20180101010203_testCommitId'"))
assertThat(jscr.shell, hasItems(containsString('git tag build_1.2.3-20180101010203_testCommitId'),
assertThat(jscr.shell, hasItems(containsString("git commit -m 'update version 1.2.3-20180101010203_testCommitId'"),
containsString('git tag build_1.2.3-20180101010203_testCommitId'),
containsString('git push myGitSshUrl build_1.2.3-20180101010203_testCommitId')))
}
@ -101,7 +101,7 @@ class ArtifactSetVersionTest extends BasePiperTest {
void testVersioningCustomGitUserAndEMail() {
jsr.step.artifactSetVersion(script: jsr.step, juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test')
assertThat(jscr.shell, hasItem("git -c user.email=\"test@test.com\" -c user.name=\"test\" commit -m 'update version 1.2.3-20180101010203_testCommitId'"))
assertThat(jscr.shell, hasItem(containsString("git -c user.email=\"test@test.com\" -c user.name=\"test\" commit -m 'update version 1.2.3-20180101010203_testCommitId'")))
}
@Test

View File

@ -86,21 +86,24 @@ def call(Map parameters = [:], Closure body = null) {
sh 'git add .'
sshagent([config.gitSshKeyCredentialsId]) {
def gitUserMailConfig = ''
if (config.gitUserName && config.gitUserEMail)
gitUserMailConfig = "-c user.email=\"${config.gitUserEMail}\" -c user.name=\"${config.gitUserName}\""
def gitConfig = []
try {
sh "git ${gitUserMailConfig} commit -m 'update version ${newVersion}'"
} catch (e) {
error "[${STEP_NAME}]git commit failed: ${e}"
}
if(config.gitUserEMail) gitConfig.add("-c user.email=\"${config.gitUserEMail}\"")
if(config.gitUserName) gitConfig.add("-c user.name=\"${config.gitUserName}\"")
gitConfig = gitConfig.join(' ')
try {
sh """#!/bin/bash
git tag ${config.tagPrefix}${newVersion}
git push ${config.gitSshUrl} ${config.tagPrefix}${newVersion}"""
git ${gitConfig} commit -m 'update version ${newVersion}'
git tag ${config.tagPrefix}${newVersion}"""
config.gitCommitId = gitUtils.getGitCommitIdOrNull()
} catch (e) {
error "[${STEP_NAME}]git commit and tag failed: ${e}"
}
sshagent([config.gitSshKeyCredentialsId]) {
sh "git push ${config.gitSshUrl} ${config.tagPrefix}${newVersion}"
}
}