Skip to content

Task: Bootstrap acr-push pipeline #3091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 81 additions & 2 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ variables:
BuildAgent: ${{ parameters.BuildAgent }}
GitUserEmail: "GraphTooling@service.microsoft.com"
GitUserName: "Microsoft Graph DevX Tooling"
REGISTRY: 'msgraphprodregistry.azurecr.io'
IMAGE_NAME: 'public/microsoftgraph/powershell'
PREVIEW_BRANCH: 'refs/heads/main' # Updated to target your branch

trigger:
branches:
include:
- main
- dev
tags:
include:
- v*

pr:
branches:
include:
Expand Down Expand Up @@ -156,7 +163,79 @@ extends:
nuGetFeedType: external
publishFeedCredentials: 'microsoftgraph PowerShell Gallery connection'

- stage: PushDockerImageToRegistry
condition: and(or(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])), not(contains(variables['Build.SourceBranch'], '-preview')))
dependsOn: []
displayName: 'Push docker image'
jobs:
- job: PushDockerImage
displayName: 'Push docker image'
pool:
name: Azure-Pipelines-1ESPT-ExDShared
image: ubuntu-latest
os: linux
steps:
- checkout: self

# Display the contents of the Build.SourcesDirectory
- bash: |
echo "Build.SourcesDirectory: $(Build.SourcesDirectory)"
ls -la $(Build.SourcesDirectory)
displayName: 'List contents of Build.SourcesDirectory'

- task: AzureCLI@2
displayName: "Log in to Azure Container Registry"
inputs:
azureSubscription: 'ACR Images Push Service Connection' # service connection
scriptType: 'bash'
scriptLocation: 'inlineScript'
'inlineScript': |
az acr login --name $(REGISTRY)
- powershell: |
$date = Get-Date -Format "yyyyMMdd"
Write-Host "##vso[task.setvariable variable=currentDate]$date"

- script: |
docker run --privileged --rm tonistiigi/binfmt --install all
displayName: 'Enable multi-platform builds'

- script: |
docker buildx create --use --name mybuilder
displayName: 'Set up Docker BuildX'

- powershell: |
$version = $Env:BUILD_SOURCEBRANCH.replace("refs/tags/", "")
Write-Output "##vso[task.setvariable variable=version]$version"
displayName: 'Get truncated run number'

- bash: |
echo "Build Number: $(Build.BuildNumber)"
# Extract the last 3 characters for the run number
runnumber=$(echo "$(Build.BuildNumber)" | grep -o '[0-9]\+$')
echo "Extracted Run Number: $runnumber"

# If extraction fails, set a default
if [ -z "$runnumber" ]; then
echo "Extraction failed, using default value"
runnumber=$(date +"%S%N" | cut -c1-3)
echo "Generated fallback run number: $runnumber"
fi

# Set the variable for later steps
echo "##vso[task.setvariable variable=RUNNUMBER]$runnumber"
echo "##vso[task.setvariable variable=RUNNUMBER;isOutput=true]$runnumber"
displayName: 'Get truncated run number'
name: getrunnumber

- bash: |
echo "Building docker images"
# Format the date to be compatible with Docker tags
formatted_date=$(date +"%Y%m%d%H%M%S")
docker buildx build \
--platform linux/amd64 \
--push \
-t "$(REGISTRY)/$(IMAGE_NAME):latest" \
-t "$(REGISTRY)/$(IMAGE_NAME):$formatted_date.$RUNNUMBER" \
"$(Build.SourcesDirectory)"
displayName: 'Build and push docker images'



Loading