Skip to content

Commit

Permalink
Fix: Private repos can not run terraform plan on PR (#1264)
Browse files Browse the repository at this point in the history
* Try wrapping in withCredentials
  • Loading branch information
reespozzi authored Sep 2, 2024
1 parent a1ef8c9 commit 7dcfa0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -ex
set -x

git fetch origin master:master
USER_NAME=${1}
BEARER_TOKEN=${2}

git remote set-url origin $(git config remote.origin.url | sed "s/github.com/${USER_NAME}:${BEARER_TOKEN}@github.com/g")
git fetch origin master:master
git diff -s --exit-code master infrastructure/
20 changes: 12 additions & 8 deletions vars/onTerraformChangeInPR.groovy
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
def call(Closure block) {
def credentialsId = env.GIT_CREDENTIALS_ID
folderExists('infrastructure') {
writeFile file: 'check-infrastructure-files-changed.sh', text: libraryResource('uk/gov/hmcts/infrastructure/check-infrastructure-files-changed.sh')

def infraFolderHasChanges = sh(
script: "chmod +x check-infrastructure-files-changed.sh\n" +
" ./check-infrastructure-files-changed.sh",
returnStatus: true
)
sh 'rm check-infrastructure-files-changed.sh'
if (infraFolderHasChanges == 1) {
return block.call()
withCredentials([usernamePassword(credentialsId: credentialsId, passwordVariable: 'BEARER_TOKEN', usernameVariable: 'APP_ID')]) {
def bearerToken = env.BEARER_TOKEN
def infraFolderHasChanges = sh(
script: "chmod +x check-infrastructure-files-changed.sh\n" +
" ./check-infrastructure-files-changed.sh $credentialsId $bearerToken",
returnStatus: true
)
sh 'rm check-infrastructure-files-changed.sh'
if (infraFolderHasChanges == 1) {
return block.call()
}
}
}
}

0 comments on commit 7dcfa0f

Please sign in to comment.