Skip to content
Open
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
35 changes: 29 additions & 6 deletions .azure-pipelines/trigger-reference-docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ name: Azure CLI Trigger Reference Docs CI

trigger:
branches:
exclude:
- '*'
tags:
include:
- release
- release-lts-*
- test-release-*
- azure-cli-*
Comment thread
wangzelin007 marked this conversation as resolved.

pr: none

Expand All @@ -19,7 +20,6 @@ variables:
jobs:
- job: TriggerReferenceDocsCI
displayName: 'Queue Microsoft Learn Docs Reference CI'
condition: or(eq(variables['Build.SourceBranchName'], 'release'), startsWith(variables['Build.SourceBranchName'], 'release-lts-'), startsWith(variables['Build.SourceBranchName'], 'test-release-'))
pool:
name: ${{ variables.ubuntu_pool }}
steps:
Expand All @@ -35,7 +35,30 @@ jobs:
$project = $env:AdoProject
$thisRepoLink = $env:ThisRepoLink
$thisRunLink = $env:ThisRunLink
$triggerBranch = $env:ReleaseBranch
$tagName = $env:TagName

# Resolve the release's target_commitish ('release' = latest, 'release-lts-<ver>' = LTS) to pick
# the matching docs pipeline. Never guess: retry transient errors, but a 404 (tag with no Release)
# or exhausted retries fail the job so a release is never queued against the wrong pipeline.
$triggerBranch = $null
for ($attempt = 1; $attempt -le 5; $attempt++) {
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/Azure/azure-cli/releases/tags/$tagName" -Headers @{ 'User-Agent' = 'azure-cli-ado' }
$triggerBranch = $release.target_commitish
break
}
catch {
if ([int]$_.Exception.Response.StatusCode -eq 404) {
throw "Tag '$tagName' exists but has no GitHub Release; aborting without queuing."
}
Write-Host "Release lookup attempt $attempt failed, retrying... $_"
Start-Sleep -Seconds (5 * $attempt)
}
}
if (-not $triggerBranch) {
throw "Could not resolve target_commitish for tag '$tagName' after retries; aborting."
}

$definitionId = $triggerBranch -like 'release-lts-*' ? $env:AdoLtsPipelineId : $env:AdoLatestPipelineId
$variables = @("triggerBranch=$triggerBranch", "triggerFromRepo=$thisRepoLink", "triggerByPipeline=$thisRunLink")

Expand All @@ -53,6 +76,6 @@ jobs:
AdoProject: $(ADO_DocsReference_Project)
AdoLatestPipelineId: $(ADO_DocsReference_Latest_Pipeline_ID)
AdoLtsPipelineId: $(ADO_DocsReference_LTS_Pipeline_ID)
ReleaseBranch: $(Build.SourceBranchName)
TagName: $(Build.SourceBranchName)
ThisRepoLink: $(Build.Repository.Uri)
ThisRunLink: $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)
Loading