Skip to content

Commit

Permalink
make the commit an environment variable to reuse in any stage
Browse files Browse the repository at this point in the history
  • Loading branch information
7hunderbird committed Aug 9, 2024
1 parent 7d785c8 commit 9db1e44
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Jenkinsfile.cd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def shouldBail() {
pipeline {
agent any

environment {
commit = ''
}

parameters {
booleanParam(name: 'SKIP_BUILD', defaultValue: false, description: 'Set to true to skip the stage')
booleanParam(name: 'SKIP_DEPLOY', defaultValue: false, description: 'Set to true to skip the stage')
Expand All @@ -23,6 +27,14 @@ pipeline {
}
}

stage('Set Commit') {
steps {
script {
env.commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
}
}

stage('Build new AMI') {

when {
Expand All @@ -33,23 +45,20 @@ pipeline {
}

steps {
script {
commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}

retry(3){
build job: "builds/${params.app}", parameters: [
booleanParam(name: 'release', value: false),
booleanParam(name: 'notify_slack', value: true),
stringParam(name: 'slack_channel', value: "${params.slack_channel}"),
stringParam(name: 'ref', value: commit),
stringParam(name: 'ref', value: env.commit),
booleanParam(name: 'force_rebuild', value: true)
], wait: true
}
}
}

stage('Deploy to STAGING') {

when {
allOf {
expression { return !params.SKIP_DEPLOY }
Expand All @@ -61,7 +70,7 @@ pipeline {
build job: "deploys/${params.app}-vagov-staging", parameters: [
stringParam(name: 'app', value: params.app),
booleanParam(name: 'notify_slack', value: true),
stringParam(name: 'ref', value: commit),
stringParam(name: 'ref', value: env.commit),
booleanParam(name: 'migration_status', value: false)
] , wait: false
}
Expand Down

0 comments on commit 9db1e44

Please sign in to comment.