Skip to content

Commit

Permalink
Fail the execution at the end if any publishing failures
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Oct 31, 2020
1 parent ff0c784 commit a9f8cd2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ if($target -eq "test") {
}

if($target -eq "publish") {
# Only fail the run afterwards in case of any issues when publishing the docker images
$publishFailed = 0
if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) {
foreach($tag in $Builds[$Build]['Tags']) {
Write-Host "Publishing $Build => tag=$tag"
Expand All @@ -131,6 +133,9 @@ if($target -eq "publish") {
Write-Host "Publishing $Build => tag=$buildTag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag
Invoke-Expression $cmd
if($lastExitCode -ne 0) {
$publishFailed = 1
}
}
}
} else {
Expand All @@ -139,6 +144,9 @@ if($target -eq "publish") {
Write-Host "Publishing $b => tag=$tag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $tag
Invoke-Expression $cmd
if($lastExitCode -ne 0) {
$publishFailed = 1
}

if($PushVersions) {
$buildTag = "$JenkinsVersion-$tag"
Expand All @@ -148,10 +156,19 @@ if($target -eq "publish") {
Write-Host "Publishing $Build => tag=$buildTag"
$cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag
Invoke-Expression $cmd
if($lastExitCode -ne 0) {
$publishFailed = 1
}
}
}
}
}

# Fail if any issues when publising the docker images
if($publishFailed -ne 0) {
Write-Error "Publish failed!"
exit 1
}
}

if($lastExitCode -ne 0) {
Expand Down

0 comments on commit a9f8cd2

Please sign in to comment.