|
26 | 26 | client-id: ${{ secrets.ADO_SP_ClientID }} |
27 | 27 | tenant-id: ${{ secrets.ADO_SP_TenantID }} |
28 | 28 | allow-no-subscriptions: true |
29 | | - - name: Azure CLI |
| 29 | + - name: Trigger ADO Pipeline and Wait for Completion |
30 | 30 | uses: azure/cli@v2 |
31 | 31 | env: |
32 | 32 | ado-org: ${{secrets.ADO_ORGANIZATION}} |
|
35 | 35 | commit-id: ${{ github.sha }} |
36 | 36 | with: |
37 | 37 | inlineScript: | |
38 | | - az pipelines build queue --definition-id ${{ env.ado-pipeline-id }} --organization ${{ env.ado-org }} --project ${{ env.ado-project }} --variables commit_id=${{ env.commit-id }} |
| 38 | + # Trigger the pipeline and capture the build ID |
| 39 | + echo "Triggering ADO pipeline..." |
| 40 | + BUILD_RESULT=$(az pipelines build queue \ |
| 41 | + --definition-id ${{ env.ado-pipeline-id }} \ |
| 42 | + --organization ${{ env.ado-org }} \ |
| 43 | + --project ${{ env.ado-project }} \ |
| 44 | + --variables commit_id=${{ env.commit-id }} \ |
| 45 | + --output json) |
| 46 | + |
| 47 | + BUILD_ID=$(echo $BUILD_RESULT | jq -r '.id') |
| 48 | + echo "Pipeline triggered with Build ID: $BUILD_ID" |
| 49 | + |
| 50 | + if [ "$BUILD_ID" = "null" ] || [ -z "$BUILD_ID" ]; then |
| 51 | + echo "Failed to get build ID from pipeline trigger" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + |
| 55 | + # Wait for the build to complete |
| 56 | + echo "Waiting for build $BUILD_ID to complete..." |
| 57 | + while true; do |
| 58 | + BUILD_JSON=$(az pipelines build show \ |
| 59 | + --id $BUILD_ID \ |
| 60 | + --organization ${{ env.ado-org }} \ |
| 61 | + --project ${{ env.ado-project }} \ |
| 62 | + --output json) |
| 63 | + |
| 64 | + BUILD_STATUS=$(echo "$BUILD_JSON" | jq -r '.status') |
| 65 | + BUILD_RESULT_STATUS=$(echo "$BUILD_JSON" | jq -r '.result // "none"') |
| 66 | + |
| 67 | + echo "Current status: $BUILD_STATUS, Result: $BUILD_RESULT_STATUS" |
| 68 | + |
| 69 | + # Check if build is completed |
| 70 | + if [ "$BUILD_STATUS" = "completed" ]; then |
| 71 | + echo "Build completed with result: $BUILD_RESULT_STATUS" |
| 72 | + |
| 73 | + # Check if the build was successful |
| 74 | + if [ "$BUILD_RESULT_STATUS" = "succeeded" ]; then |
| 75 | + echo "✅ ADO pipeline build succeeded!" |
| 76 | + exit 0 |
| 77 | + elif [ "$BUILD_RESULT_STATUS" = "partiallySucceeded" ]; then |
| 78 | + echo "⚠️ ADO pipeline build partially succeeded" |
| 79 | + exit 1 |
| 80 | + else |
| 81 | + echo "❌ ADO pipeline build failed with result: $BUILD_RESULT_STATUS" |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + fi |
| 85 | + |
| 86 | + # Check for other terminal states |
| 87 | + if [ "$BUILD_STATUS" = "cancelling" ] || [ "$BUILD_STATUS" = "cancelled" ]; then |
| 88 | + echo "❌ ADO pipeline build was cancelled" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + |
| 92 | + # Wait 60 seconds before checking again |
| 93 | + echo "Build still running... waiting 60 seconds" |
| 94 | + sleep 60 |
| 95 | + done |
0 commit comments