Skip to content

Commit

Permalink
Empty 'gitops' folder before git clone command (#49)
Browse files Browse the repository at this point in the history
When a build agent uses the same workspace for multi stage the gitops folder is not empty
after first stage. I.e.  git clone ${origin} gitops fails due to not empty folder
* Change to use mktmp folder for gitops repo cloning
  • Loading branch information
tomsolem committed May 12, 2021
1 parent 72e44f4 commit 9ece07a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions vars/acePushConfigToGit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ void call(Map opts = [:]) {

target = readYaml file: 'target-data/target.yaml'
cfg = readYaml file: opts.aceFile ?: 'ace.yaml'
sh "gitOpsfolder=$(mktemp -d gitOpsXXXXXX)"
Map gitops = cfg.gitops ?: [:]
String gitopsRepo = gitops.repo
String strategy = gitops.strategy ?: 'path'
Expand Down Expand Up @@ -32,25 +33,25 @@ void call(Map opts = [:]) {
git config --global user.email jenkins@tietoevry.com
git config --global user.name "Jenkins the autonomous"
git clone ${origin} gitops
cd gitops
git clone ${origin} ${gitOpsfolder}
cd ${gitOpsfolder}
git fetch -a
"""

if (strategy == 'branch') {
String pushToBranch = gitops.pushToBranch ?: 'test'

String branches = sh(
script: 'cd gitops; git branch -a', returnStdout: true).trim()
script: 'cd ${gitOpsfolder}; git branch -a', returnStdout: true).trim()
println "[ace] Got branches ${branches}"
Boolean branchExists = branches.contains("remotes/origin/${pushToBranch}")
println "[ace] Branch ${pushToBranch} exists."

gitCheckoutArgs = branchExists ? '' : '-b'
sh "cd gitops; git checkout ${gitCheckoutArgs} ${pushToBranch}"
sh "cd ${gitOpsfolder}; git checkout ${gitCheckoutArgs} ${pushToBranch}"

sh """
cd gitops
cd ${gitOpsfolder}
CHANGED=''
[ ! -d "${target.name}" ] && {
cp -R ../target-data ${target.name}
Expand All @@ -77,7 +78,7 @@ void call(Map opts = [:]) {
String targetFolder = "${target.name}/${firstEnv}"

sh """
cd gitops
cd ${gitOpsfolder}
CHANGED=''
[ ! -d "${targetFolder}" ] && {
Expand Down

0 comments on commit 9ece07a

Please sign in to comment.