|
80 | 80 | artifact: 'deploy-changes-$(kube_namespace)' |
81 | 81 | publishLocation: 'pipeline' |
82 | 82 |
|
| 83 | + # Validation Tag exists in Container Registry |
| 84 | + - task: Bash@3 |
| 85 | + displayName: 'Determine image tag' |
| 86 | + inputs: |
| 87 | + targetType: inline |
| 88 | + script: | |
| 89 | + GIT_COMMIT=$(git rev-parse --short HEAD) |
| 90 | + IMAGE_TAG="$(Build.SourceBranchName)-${GIT_COMMIT}" |
| 91 | +
|
| 92 | + echo "Git commit: ${GIT_COMMIT}" |
| 93 | + echo "Image tag: ${IMAGE_TAG}" |
| 94 | +
|
| 95 | + echo "##vso[task.setvariable variable=GIT_COMMIT]${GIT_COMMIT}" |
| 96 | + echo "##vso[task.setvariable variable=IMAGE_TAG]${IMAGE_TAG}" |
| 97 | +
|
| 98 | + # Validation Tag exists in Container Registry |
| 99 | + - task: AzureCLI@2 |
| 100 | + displayName: 'Validate image exists for $(serviceName)' |
| 101 | + inputs: |
| 102 | + azureSubscription: 'NHSNLink-RG ARM' |
| 103 | + scriptType: bash |
| 104 | + scriptLocation: inlineScript |
| 105 | + inlineScript: | |
| 106 | + set -e |
| 107 | +
|
| 108 | + IMAGE_REPO="link-$(repoName)" |
| 109 | + IMAGE_TAG="$(Build.SourceBranchName)-$(GIT_COMMIT)" |
| 110 | +
|
| 111 | + echo "Checking if image exists in ACR..." |
| 112 | + echo "Registry: $(containerRegistry)" |
| 113 | + echo "Repository: ${IMAGE_REPO}" |
| 114 | + echo "Tag: ${IMAGE_TAG}" |
| 115 | + echo "Full image: $(containerRegistry)/${IMAGE_REPO}:${IMAGE_TAG}" |
| 116 | +
|
| 117 | + if ! az acr repository show \ |
| 118 | + --name "$(containerRegistry)" \ |
| 119 | + --image "${IMAGE_REPO}:${IMAGE_TAG}" \ |
| 120 | + --output none; then |
| 121 | +
|
| 122 | + echo "##vso[task.logissue type=error]Image does NOT exist in ACR: $(containerRegistry)/${IMAGE_REPO}:${IMAGE_TAG}" |
| 123 | + echo "Deployment for $(serviceName) has been stopped." |
| 124 | +
|
| 125 | + exit 1 |
| 126 | + fi |
| 127 | +
|
| 128 | + echo "Image exists in ACR." |
| 129 | + echo "Continuing with deployment..." |
| 130 | +
|
83 | 131 | - job: Deploy |
84 | 132 | dependsOn: Summarize |
85 | 133 | condition: succeeded() |
|
0 commit comments