Skip to content

Moving trigger pipeline from git Action to ADO pipeline #90

Moving trigger pipeline from git Action to ADO pipeline

Moving trigger pipeline from git Action to ADO pipeline #90

Workflow file for this run

name: Build TestStream.Runner
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.0.x'
- name: Build the project
run: dotnet build TestStream.Runner/TestStream.Runner.csproj
# - name: Trigger Azure DevOps Pipeline
# env:
# AZURE_DEVOPS_ORG: ${{ vars.AZURE_DEVOPS_ORG }}
# AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream
# AZURE_DEVOPS_PIPELINE_ID: 111
# AZURE_POOL_NAME: ${{ vars.AZURE_POOL_NAME }}
# GITHUB_HEAD_REF: ${{ github.head_ref }}
# run: |
# # Validate required environment variables
# for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME GITHUB_HEAD_REF; do
# if [ -z "${!var}" ]; then
# echo "Error: Required environment variable $var is not set"
# exit 1
# fi
# done
# # Define the Azure DevOps organization, project, and pipeline
# organization="${AZURE_DEVOPS_ORG}"
# project="${AZURE_DEVOPS_PROJECT}"
# pipelineId="${AZURE_DEVOPS_PIPELINE_ID}"
# poolName="${AZURE_POOL_NAME}"
# branch="refs/heads/${GITHUB_HEAD_REF}"
# # Encode the PAT
# patEncoded=$(echo -n ":${{ secrets.AZURE_DEVOPS_PAT }}" | base64)
# # Define the headers
# headers=(
# -H "Authorization: Basic $patEncoded"
# -H "Content-Type: application/json"
# )
# # Get the pool ID
# url="https://dev.azure.com/${organization}/_apis/distributedtask/pools?poolName=${poolName}&api-version=7.1"
# AZP_POOL_AGENTS=$(curl -s "${headers[@]}" -X GET "$url")
# poolId=$(echo "$AZP_POOL_AGENTS" | jq -r '.value[0].id')
# echo "Pool ID: $poolId"
# # Define the URL to get all agents in the pool
# url="https://dev.azure.com/${organization}/_apis/distributedtask/pools/${poolId}/agents?includeCapabilities=true&api-version=7.1"
# response=$(curl -s -w "%{http_code}" "${headers[@]}" -X GET "$url")
# http_code=${response: -3}
# content=${response::-3}
# if [ $http_code -eq 200 ]; then
# # Extract all userCapabilities names for online and enabled agents as a unique list
# capabilityNames=$(echo "$content" | jq -r '[.value[] | select(.status == "online" and .enabled == true) | .userCapabilities | keys] | unique | flatten | join("\n- ")')
# else
# echo "Failed to retrieve agent capabilities. HTTP Status Code: $http_code"
# echo "Response: \"$content\""
# exit 1
# fi
# echo "Unique userCapabilities names: \"$capabilityNames\""
# # Prepare the parameters
# parametersJson=$(jq -n --arg appComponents "- $capabilityNames" '{templateParameters: {appComponents: $appComponents}}')
# echo "Parameters: \"$parametersJson\""
# echo "Branch for PR: \"$branch\""
# # Define the request body
# bodyJson=$(jq -n --argjson parameters "$parametersJson" --arg branch "$branch" '{
# resources: {
# repositories:
# {
# self: {
# refName: $branch
# }
# }
# },
# templateParameters: $parameters.templateParameters
# }')
# echo "Request body: \"$bodyJson\""
# # Define the URL
# url="https://dev.azure.com/${organization}/${project}/_apis/pipelines/${pipelineId}/runs?api-version=7.1"
# # Trigger the pipeline
# response=$(curl -s -w "%{http_code}" "${headers[@]}" -X POST -d "$bodyJson" "$url")
# http_code=${response: -3}
# content=${response::-3}
# if [ $http_code -eq 200 ]; then
# run_id=$(echo "$content" | jq -r '.id')
# echo "Pipeline triggered successfully. Run ID: $run_id"
# else
# echo "Failed to trigger pipeline. HTTP Status Code: $http_code"
# echo "Response: $content"
# exit 1
# fi