Skip to content

Commit

Permalink
ci(jenkins): improve error handling on helm upgrade
Browse files Browse the repository at this point in the history
- delete the already created ImageStream in case the helmet upgrade fails to allow a restart of the build process
  • Loading branch information
SimonGolms committed Aug 25, 2022
1 parent fe14964 commit 3580dbb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,20 @@ def stageRolloutWithHelm(def context) {

// Go to directory where the helm chart is located
dir('chart'){
// we'll simply reuse the instance from above to do the actual helm rollout
openShiftService.helmUpgrade("${context.targetProject}", helmReleaseName, helmValuesFiles, helmValues, helmDefaultFlags, helmAdditionalFlags, helmDiff)
try {
openShiftService.helmUpgrade("${context.targetProject}", helmReleaseName, helmValuesFiles, helmValues, helmDefaultFlags, helmAdditionalFlags, helmDiff)
} catch (Exception exception) {
/**
* In case the rollout with Helm does not go through successfully, e.g. due to a faulty nginx configuration
* that prevents the pod from starting, you have to make sure that the already deployed image is deleted again,
* otherwise the elseBlock of stageWorkaroundFindOpenShiftImageOrElse will not be executed anymore.
*/
sh(
label: 'Delete deployed Imagestream Tag',
script: "oc tag --delete --namespace ${context.cdProject} ${JOB_APP_NAME}:${JOB_APP_VERSION}",
)
throw exception
}
}
}
}
Expand Down

0 comments on commit 3580dbb

Please sign in to comment.