From 7c0f6eb60325deebf9d19dab39b26749b5246ae8 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Mon, 23 Oct 2023 14:58:02 -0700 Subject: [PATCH] limit building deployment artifact + added buildArtifact variable and set it to true + in auditing stage, if there's an error, set buildArtifact to false + in build artifact stage, if buildArtifact is true, build it --- Jenkinsfile | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 41598a7..674125c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,5 @@ +def buildArtifact = true + pipeline { agent { label 'ruby && freebsd' } @@ -25,8 +27,16 @@ pipeline { stage('Audit Dependencies') { steps { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { - sh 'bundle exec ruby-audit check' - sh 'bundle exec bundle-audit check >> audit.html' + script { + try { + sh 'bundle exec ruby-audit check' + sh 'bundle exec bundle-audit check >> audit.html' + } catch (e) { + script { + buildArtifact = false + } + } + } } } } @@ -61,7 +71,11 @@ pipeline { } stage('Build production deliverable') { steps { - echo "BUILD RESULT: ${buildResult}" + when { + expression { + buildArtifact + } + } catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { sh ''' #!/usr/local/bin/bash ZIP_FILE="url-shortener_${BRANCH_NAME}_$(date "+%Y-%m-%d_%H-%M-%S").tgz"