|
| 1 | +name: Trigger Microsoft Learn Docs Reference CI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - released |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + RunAzurePipeline: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Azure Login |
| 16 | + |
| 17 | + with: |
| 18 | + client-id: ${{ secrets.ADO_DocsReference_SP_ClientID }} |
| 19 | + tenant-id: ${{ secrets.ADO_DocsReference_SP_TenantID }} |
| 20 | + allow-no-subscriptions: true |
| 21 | + |
| 22 | + - name: Run Azure Pipeline |
| 23 | + shell: pwsh |
| 24 | + env: |
| 25 | + AdoOrg: ${{secrets.ADO_DocsReference_Organization}} |
| 26 | + AdoProject: ${{secrets.ADO_DocsReference_Project}} |
| 27 | + AdoPipelineId: ${{secrets.ADO_DocsReference_JumpPipeline_ID}} |
| 28 | + CheckInterval: 60 |
| 29 | + run: | |
| 30 | + $organization = $env:AdoOrg |
| 31 | + $project = $env:AdoProject |
| 32 | + $definitionId = $env:AdoPipelineId |
| 33 | + $checkInterval = $env:CheckInterval |
| 34 | + $thisRunLink = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 35 | + $triggerBranch = 'main' |
| 36 | + $variables = @('commitAuthor=azcli', 'triggerFromRepo=https://github.com/Azure/azure-cli', "triggerBranch=$triggerBranch", "triggerByPipeline=$thisRunLink") |
| 37 | +
|
| 38 | + $output = az pipelines build queue --definition-id $definitionId --project $project --organization $organization --variables @variables | ConvertFrom-Json -AsHashtable |
| 39 | + if ($? -eq $false) |
| 40 | + { |
| 41 | + $pipelineDefinitionLink = $organization + [uri]::EscapeDataString($project) + "/_build?definitionId=$definitionId" |
| 42 | + Write-Error "Failed to queue the pipeline run for $pipelineDefinitionLink, please check above error message." |
| 43 | + } |
| 44 | + $runIdInJumpPipeline = $output.id |
| 45 | + Write-Host "runIdInJumpPipeline: $runIdInJumpPipeline" |
| 46 | + do |
| 47 | + { |
| 48 | + Start-Sleep -Seconds $checkInterval |
| 49 | + $status = az pipelines runs show --query status --id $runIdInJumpPipeline --project $project --organization $organization --output tsv |
| 50 | + $currentTime = (Get-Date -AsUTC).ToString('yyyy-MM-dd HH:mm:ss') |
| 51 | + Write-Host "[UTC $currentTime] apidrop shared jump pipeline run status: $status" |
| 52 | + } while ($status -ne 'completed') |
| 53 | + $jumpOutput = az pipelines runs show --id $runIdInJumpPipeline --project $project --organization $organization | ConvertFrom-Json -AsHashtable |
| 54 | +
|
| 55 | + $targetPipelineResult = ($jumpOutput.tags -Match 'jump_return_result_(canceled|failed|partiallySucceeded|succeeded)')[0] -replace 'jump_return_result_', '' |
| 56 | + $runId = ($jumpOutput.tags -Match 'jump_return_id_\d+')[0] -replace 'jump_return_id_', '' |
| 57 | + $triggeredTargetPipeline = $runId ? $true : $false |
| 58 | + if ($triggeredTargetPipeline) |
| 59 | + { |
| 60 | + # apidrop shared jump pipeline triggered target pipeline |
| 61 | + $printMessage = 'Triggered reference pipeline run' |
| 62 | + $printMessage += $targetPipelineResult ? " with its result $targetPipelineResult" : '' # waited for completion or not |
| 63 | + } |
| 64 | + else |
| 65 | + { |
| 66 | + # apidrop shared jump pipeline may fail to trigger target pipeline |
| 67 | + $runId = $runIdInJumpPipeline |
| 68 | + $printMessage = "Jump pipeline run with $($jumpOutput.result) state may fail to trigger reference pipeline" |
| 69 | + } |
| 70 | + $runLink = $organization + [uri]::EscapeDataString($project) + "/_build/results?buildId=$runId" |
| 71 | + $printMessage += ", for details please check: $runLink" |
| 72 | + if ($triggeredTargetPipeline) |
| 73 | + { |
| 74 | + Write-Host $printMessage |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + Write-Error $printMessage |
| 79 | + } |
0 commit comments