-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Converted containerized CI process to use docker for ease of use in ADO - Added stage to authenticate and push CI images to ACR - Added support for extracting test results and coverage files from containerized build
- Loading branch information
1 parent
68bc932
commit 0657f6a
Showing
4 changed files
with
238 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# This template is used to authenticate to Azure and push Docker images across Azure tenants. | ||
# We cannot use the simpler Docker@2 push command because MSI does not support cross-tenant authentication. | ||
|
||
parameters: | ||
- name: acrFQDN | ||
type: string | ||
- name: repository # This is both the ACR and local repository name | ||
type: string # The local and ACR image repository name | ||
- name: pushLatest | ||
type: boolean | ||
default: false | ||
|
||
steps: | ||
# Authenticate to ACR and push the image | ||
- task: AzureCLI@2 | ||
displayName: 'Authenticate to Azure and Push Docker Image' | ||
inputs: | ||
azureSubscription: 'ado-pipeline-dev-image-push' # Service connection name | ||
scriptType: bash | ||
scriptLocation: 'inlineScript' | ||
inlineScript: | | ||
set -xe | ||
echo "Authenticating to Azure and ACR..." | ||
ACR_FQDN="${{ parameters.acrFQDN }}" | ||
REGISTRY_NAME=$(echo $ACR_FQDN | cut -d'.' -f1) | ||
# Login to ACR | ||
az acr login --name $REGISTRY_NAME | ||
# List Docker images to verify the built image exists | ||
echo "Listing Docker images..." | ||
docker images | ||
# Ensure the image is available locally before tagging the build ID | ||
IMAGE_NAME="${{ parameters.repository }}:$(Build.BuildId)" | ||
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" == "" ]]; then | ||
echo "Error: Image $IMAGE_NAME not found. Exiting." | ||
exit 1 | ||
fi | ||
# Ensure the image is available locally before tagging 'latest' | ||
IMAGE_LATEST="${{ parameters.repository }}:latest" | ||
if [[ "$(docker images -q $IMAGE_LATEST 2> /dev/null)" == "" ]]; then | ||
echo "Warning: Image $IMAGE_LATEST not found. Skipping latest tag." | ||
SKIP_LATEST=true | ||
else | ||
SKIP_LATEST=false | ||
fi | ||
# Tag the image with the ACR repository for the build ID | ||
echo "Tagging image with build ID..." | ||
docker tag $IMAGE_NAME ${ACR_FQDN}/${{ parameters.repository }}:$(Build.BuildId) | ||
# If the latest image exists, tag it as well | ||
if [ "$SKIP_LATEST" == "false" ]; then | ||
echo "Tagging image with 'latest'..." | ||
docker tag $IMAGE_LATEST ${ACR_FQDN}/${{ parameters.repository }}:latest | ||
fi | ||
# Push the Docker image to ACR with build ID | ||
echo "Pushing image with build ID to ACR..." | ||
docker push ${ACR_FQDN}/${{ parameters.repository }}:$(Build.BuildId) | ||
# Optionally push the image as 'latest' | ||
if [ "${{ parameters.pushLatest }}" == "true" ] && [ "$SKIP_LATEST" == "false" ]; then | ||
echo "Pushing 'latest' tag to ACR..." | ||
docker push ${ACR_FQDN}/${{ parameters.repository }}:latest | ||
fi |
Oops, something went wrong.