77 include :
88 - main
99 - support/v1
10+ - task/move-to-deploy-stage
1011 tags :
1112 include :
1213 - ' v*'
@@ -22,7 +23,7 @@ variables:
2223 ProductBinPath : ' $(Build.SourcesDirectory)\src\Microsoft.OpenApi\bin\$(BuildConfiguration)'
2324 REGISTRY : ' msgraphprodregistry.azurecr.io'
2425 IMAGE_NAME : ' public/openapi/hidi'
25- PREVIEW_BRANCH : ' refs/heads/main '
26+ PREVIEW_BRANCH : ' refs/heads/task/move-to-deploy-stage '
2627
2728resources :
2829 repositories :
@@ -318,119 +319,119 @@ extends:
318319 assets : ' $(Pipeline.Workspace)\**\*.exe'
319320 addChangeLog : false
320321
321- - stage : Build_and_deploy_docker_images
322- displayName : ' Build and deploy docker images'
323- condition : or(eq(variables['build.sourceBranch'], 'refs/tags/v'), eq(variables['build.sourceBranch'], variables['PREVIEW_BRANCH']))
324- dependsOn : build
325- pool :
326- name : Azure-Pipelines-1ESPT-ExDShared
327- image : ubuntu-latest
328- os : linux
329- jobs :
330- - job : buildAndPush
331- steps :
332- - task : AzureCLI@2
333- displayName : ' Login to Azure Container Registry'
334- inputs :
335- azureSubscription : ' ACR Images Push Service Connection'
336- scriptType : bash
337- scriptLocation : inlineScript
338- inlineScript : |
339- az acr login --name msgraphprodregistry
340-
341- - powershell : |
342- $content = [XML](Get-Content ./Directory.Build.props)
343- Write-Host "XML loaded, finding version..."
344-
345- # Handle PropertyGroup as either a single element or array
346- $version = $null
347- if ($content.Project.PropertyGroup -is [array]) {
348- Write-Host "PropertyGroup is an array, checking each entry..."
349- foreach ($pg in $content.Project.PropertyGroup) {
350- if ($pg.Version) {
351- $version = $pg.Version.ToString().Trim()
352- Write-Host "Found version in PropertyGroup array: $version"
353- break
322+ - deployment : deploy_docker_image
323+ displayName : ' Build and deploy docker images'
324+ condition : or(contains(variables['build.sourceBranch'], 'refs/tags/v'), eq(variables['build.sourceBranch'], variables['PREVIEW_BRANCH']))
325+ dependsOn : build
326+ pool :
327+ name : Azure-Pipelines-1ESPT-ExDShared
328+ image : ubuntu-latest
329+ os : linux
330+ jobs :
331+ - job : buildAndPush
332+ steps :
333+ - task : AzureCLI@2
334+ displayName : ' Login to Azure Container Registry'
335+ inputs :
336+ azureSubscription : ' ACR Push Test'
337+ scriptType : bash
338+ scriptLocation : inlineScript
339+ inlineScript : |
340+ az acr login --name msgraphpperegistry
341+
342+ - powershell : |
343+ $content = [XML](Get-Content ./Directory.Build.props)
344+ Write-Host "XML loaded, finding version..."
345+
346+ # Handle PropertyGroup as either a single element or array
347+ $version = $null
348+ if ($content.Project.PropertyGroup -is [array]) {
349+ Write-Host "PropertyGroup is an array, checking each entry..."
350+ foreach ($pg in $content.Project.PropertyGroup) {
351+ if ($pg.Version) {
352+ $version = $pg.Version.ToString().Trim()
353+ Write-Host "Found version in PropertyGroup array: $version"
354+ break
355+ }
356+ }
357+ } else {
358+ # Single PropertyGroup
359+ $version = $content.Project.PropertyGroup.Version
360+ if ($version) {
361+ $version = $version.ToString().Trim()
362+ Write-Host "Found version in PropertyGroup: $version"
354363 }
355364 }
356- } else {
357- # Single PropertyGroup
358- $version = $content.Project.PropertyGroup.Version
359- if ($version) {
360- $version = $version.ToString().Trim()
361- Write-Host "Found version in PropertyGroup: $version"
365+
366+ if (-not $version) {
367+ Write-Host "##vso[task.logissue type=error]Version not found in Directory.Build.props"
368+ exit 1
362369 }
363- }
364-
365- if (-not $version) {
366- Write-Host "##vso[task.logissue type=error]Version not found in Directory.Build.props"
367- exit 1
368- }
369-
370- Write-Host "Version found: $version"
371- Write-Host "##vso[task.setvariable variable=version;isoutput=true]$version"
372- Write-Host "##vso[task.setvariable variable=VERSION]$version"
373- displayName: 'Get version from csproj'
374- name: getversion
375-
376- - bash : |
377- # Debug output to verify version variable
378- echo "Version from previous step: $VERSION"
379- displayName: 'Verify version variable'
380-
381- - bash : |
382- echo "Build Number: $(Build.BuildNumber)"
383- # Extract the last 3 characters for the run number
384- runnumber=$(echo "$(Build.BuildNumber)" | grep -o '[0-9]\+$')
385- echo "Extracted Run Number: $runnumber"
386-
387- # If extraction fails, set a default
388- if [ -z "$runnumber" ]; then
389- echo "Extraction failed, using default value"
390- runnumber=$(date +"%S%N" | cut -c1-3)
391- echo "Generated fallback run number: $runnumber"
392- fi
393-
394- # Set the variable for later steps
395- echo "##vso[task.setvariable variable=RUNNUMBER]$runnumber"
396- echo "##vso[task.setvariable variable=RUNNUMBER;isOutput=true]$runnumber"
397- displayName: 'Get truncated run number'
398- name: getrunnumber
399- condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
400-
401- - bash : |
402- date=$(date +'%Y%m%d')
403- echo "Date value: $date"
404- echo "##vso[task.setvariable variable=BUILDDATE;isOutput=true]$date"
405- echo "##vso[task.setvariable variable=BUILDDATE]$date"
406- displayName: 'Get current date'
407- name: setdate
408- condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
409-
410- - bash : |
411- echo "Building Docker image..."
412- echo "Using build date: ${BUILDDATE}"
413- # Using quotes around tags to prevent flag interpretation
414- docker build \
415- -t "$(REGISTRY)/$(IMAGE_NAME):nightly" \
416- -t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
417- "$(Build.SourcesDirectory)"
418-
419- echo "Pushing Docker image with nightly tag..."
420- docker push "$(REGISTRY)/$(IMAGE_NAME):nightly"
421- docker push "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}"
422- displayName: 'Build and Push Nightly Image'
423- condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
424-
425- - bash : |
426- echo "Building Docker image for release..."
427- docker build \
428- -t "$(REGISTRY)/$(IMAGE_NAME):latest" \
429- -t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
430- "$(Build.SourcesDirectory)"
431-
432- echo "Pushing Docker image with latest and version tags..."
433- docker push "$(REGISTRY)/$(IMAGE_NAME):latest"
434- docker push "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}"
435- displayName: 'Build and Push Release Image'
436- condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/v')
370+
371+ Write-Host "Version found: $version"
372+ Write-Host "##vso[task.setvariable variable=version;isoutput=true]$version"
373+ Write-Host "##vso[task.setvariable variable=VERSION]$version"
374+ displayName: 'Get version from csproj'
375+ name: getversion
376+
377+ - bash : |
378+ # Debug output to verify version variable
379+ echo "Version from previous step: $VERSION"
380+ displayName: 'Verify version variable'
381+
382+ - bash : |
383+ echo "Build Number: $(Build.BuildNumber)"
384+ # Extract the last 3 characters for the run number
385+ runnumber=$(echo "$(Build.BuildNumber)" | grep -o '[0-9]\+$')
386+ echo "Extracted Run Number: $runnumber"
387+
388+ # If extraction fails, set a default
389+ if [ -z "$runnumber" ]; then
390+ echo "Extraction failed, using default value"
391+ runnumber=$(date +"%S%N" | cut -c1-3)
392+ echo "Generated fallback run number: $runnumber"
393+ fi
394+
395+ # Set the variable for later steps
396+ echo "##vso[task.setvariable variable=RUNNUMBER]$runnumber"
397+ echo "##vso[task.setvariable variable=RUNNUMBER;isOutput=true]$runnumber"
398+ displayName: 'Get truncated run number'
399+ name: getrunnumber
400+ condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
401+
402+ - bash : |
403+ date=$(date +'%Y%m%d')
404+ echo "Date value: $date"
405+ echo "##vso[task.setvariable variable=BUILDDATE;isOutput=true]$date"
406+ echo "##vso[task.setvariable variable=BUILDDATE]$date"
407+ displayName: 'Get current date'
408+ name: setdate
409+ condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
410+
411+ - bash : |
412+ echo "Building Docker image..."
413+ echo "Using build date: ${BUILDDATE}"
414+ # Using quotes around tags to prevent flag interpretation
415+ docker build \
416+ -t "$(REGISTRY)/$(IMAGE_NAME):nightly" \
417+ -t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
418+ "$(Build.SourcesDirectory)"
419+
420+ echo "Pushing Docker image with nightly tag..."
421+ docker push "$(REGISTRY)/$(IMAGE_NAME):nightly"
422+ docker push "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}"
423+ displayName: 'Build and Push Nightly Image'
424+ condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
425+
426+ - bash : |
427+ echo "Building Docker image for release..."
428+ docker build \
429+ -t "$(REGISTRY)/$(IMAGE_NAME):latest" \
430+ -t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
431+ "$(Build.SourcesDirectory)"
432+
433+ echo "Pushing Docker image with latest and version tags..."
434+ docker push "$(REGISTRY)/$(IMAGE_NAME):latest"
435+ docker push "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}"
436+ displayName: 'Build and Push Release Image'
437+ condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/v')
0 commit comments