Skip to content

Commit a281561

Browse files
committed
Adding ACR Image Validation
1 parent e54a921 commit a281561

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Azure_Pipelines/_deploy_all_services.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,54 @@ jobs:
8080
artifact: 'deploy-changes-$(kube_namespace)'
8181
publishLocation: 'pipeline'
8282

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+
83131
- job: Deploy
84132
dependsOn: Summarize
85133
condition: succeeded()

0 commit comments

Comments
 (0)