Skip to content
Merged
Show file tree
Hide file tree
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
121 changes: 121 additions & 0 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ pr:
include:
- main
- support/v1

variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
ProductBinPath: '$(Build.SourcesDirectory)\src\Microsoft.OpenApi\bin\$(BuildConfiguration)'
REGISTRY: 'msgraphprodregistry.azurecr.io'
IMAGE_NAME: 'public/openapi/hidi'
PREVIEW_BRANCH: 'refs/heads/main'

resources:
repositories:
- repository: 1ESPipelineTemplates
Expand Down Expand Up @@ -313,3 +318,119 @@ extends:
assets: '$(Pipeline.Workspace)\**\*.exe'
addChangeLog: false

- stage: Build_and_deploy_docker_images
displayName: 'Build and deploy docker images'
condition: or(eq(variables['build.sourceBranch'], 'refs/tags/v'), eq(variables['build.sourceBranch'], variables['PREVIEW_BRANCH']))
dependsOn: build
pool:
name: Azure-Pipelines-1ESPT-ExDShared
image: ubuntu-latest
os: linux
jobs:
- job: buildAndPush
steps:
- task: AzureCLI@2
displayName: 'Login to Azure Container Registry'
inputs:
azureSubscription: 'ACR Images Push Service Connection'
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
az acr login --name msgraphprodregistry

- powershell: |
$content = [XML](Get-Content ./Directory.Build.props)
Write-Host "XML loaded, finding version..."

# Handle PropertyGroup as either a single element or array
$version = $null
if ($content.Project.PropertyGroup -is [array]) {
Write-Host "PropertyGroup is an array, checking each entry..."
foreach ($pg in $content.Project.PropertyGroup) {
if ($pg.Version) {
$version = $pg.Version.ToString().Trim()
Write-Host "Found version in PropertyGroup array: $version"
break
}
}
} else {
# Single PropertyGroup
$version = $content.Project.PropertyGroup.Version
if ($version) {
$version = $version.ToString().Trim()
Write-Host "Found version in PropertyGroup: $version"
}
}

if (-not $version) {
Write-Host "##vso[task.logissue type=error]Version not found in Directory.Build.props"
exit 1
}

Write-Host "Version found: $version"
Write-Host "##vso[task.setvariable variable=version;isoutput=true]$version"
Write-Host "##vso[task.setvariable variable=VERSION]$version"
displayName: 'Get version from csproj'
name: getversion

- bash: |
# Debug output to verify version variable
echo "Version from previous step: $VERSION"
displayName: 'Verify version variable'

- 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
condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])

- bash: |
date=$(date +'%Y%m%d')
echo "Date value: $date"
echo "##vso[task.setvariable variable=BUILDDATE;isOutput=true]$date"
echo "##vso[task.setvariable variable=BUILDDATE]$date"
displayName: 'Get current date'
name: setdate
condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])

- bash: |
echo "Building Docker image..."
echo "Using build date: ${BUILDDATE}"
# Using quotes around tags to prevent flag interpretation
docker build \
-t "$(REGISTRY)/$(IMAGE_NAME):nightly" \
-t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
"$(Build.SourcesDirectory)"

echo "Pushing Docker image with nightly tag..."
docker push "$(REGISTRY)/$(IMAGE_NAME):nightly"
docker push "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}"
displayName: 'Build and Push Nightly Image'
condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])

- bash: |
echo "Building Docker image for release..."
docker build \
-t "$(REGISTRY)/$(IMAGE_NAME):latest" \
-t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
"$(Build.SourcesDirectory)"

echo "Pushing Docker image with latest and version tags..."
docker push "$(REGISTRY)/$(IMAGE_NAME):latest"
docker push "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}"
displayName: 'Build and Push Release Image'
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/v')
54 changes: 0 additions & 54 deletions .github/workflows/docker.yml

This file was deleted.

Loading