From 5a15d54743152b91148543a61bbbad559ffcb37a Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 14:50:34 +0200 Subject: [PATCH 01/13] adding basic element --- .github/workflows/build.yml | 186 ++++++++++++++++++------------------ azure-boostrap.yaml | 73 ++++++++++++++ 2 files changed, 166 insertions(+), 93 deletions(-) create mode 100644 azure-boostrap.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce4c58a..e1f94a1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,97 +21,97 @@ jobs: - 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 + # - 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 \ No newline at end of file diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml new file mode 100644 index 0000000..5b92852 --- /dev/null +++ b/azure-boostrap.yaml @@ -0,0 +1,73 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +trigger: + branches: + include: + - main + - develop + - release-* + paths: + exclude: + - .github_changelog_generator + - .gitignore + - CHANGELOG.md + - CODE_OF_CONDUCT.md + - LICENSE.md + - README.md + - NuGet.Config + - assets/* + - config/* + - .github/* + +# PR always trigger build +pr: + autoCancel: true + +jobs: +- job: Trigger + displayName: Trigger Azure Dev Ops build and test pipeline + runs-on: ubuntu-latest + + steps: + - name: Trigger Azure DevOps Pipeline + env: + AZURE_DEVOPS_ORG: nanoFramework + AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream + AZURE_DEVOPS_PIPELINE_ID: 111 + AZURE_POOL_NAME: TestStream + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) + run: | + # Validate required environment variables + for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME; 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/${{ Build.SourceBranchName }}" + + # Encode the PAT + patEncoded=$(echo -n ":${{ 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}/_ \ No newline at end of file From c7a9f4b0fc2539760d9a324d8d0461fdbf611040 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 14:57:36 +0200 Subject: [PATCH 02/13] fixing for ADO --- azure-boostrap.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 5b92852..f03ed0e 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -27,17 +27,18 @@ pr: jobs: - job: Trigger displayName: Trigger Azure Dev Ops build and test pipeline - runs-on: ubuntu-latest + pool: + vmImage: 'ubuntu-latest' steps: - - name: Trigger Azure DevOps Pipeline + - displayName: 'Trigger Azure DevOps Pipeline' env: AZURE_DEVOPS_ORG: nanoFramework AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream AZURE_DEVOPS_PIPELINE_ID: 111 AZURE_POOL_NAME: TestStream AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - run: | + script: | # Validate required environment variables for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME; do if [ -z "${!var}" ]; then From de66ad4a880f53d0f29315f2b9f25e41e1540b99 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 14:58:53 +0200 Subject: [PATCH 03/13] adjusting for ADO --- azure-boostrap.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index f03ed0e..e7abbbd 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -31,14 +31,7 @@ jobs: vmImage: 'ubuntu-latest' steps: - - displayName: 'Trigger Azure DevOps Pipeline' - env: - AZURE_DEVOPS_ORG: nanoFramework - AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream - AZURE_DEVOPS_PIPELINE_ID: 111 - AZURE_POOL_NAME: TestStream - AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - script: | + - script: | # Validate required environment variables for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME; do if [ -z "${!var}" ]; then @@ -71,4 +64,11 @@ jobs: echo "Pool ID: $poolId" # Define the URL to get all agents in the pool - url="https://dev.azure.com/${organization}/_ \ No newline at end of file + url="https://dev.azure.com/${organization}/_ + displayName: 'Trigger Azure DevOps Pipeline' + env: + AZURE_DEVOPS_ORG: nanoFramework + AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream + AZURE_DEVOPS_PIPELINE_ID: 111 + AZURE_POOL_NAME: TestStream + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) \ No newline at end of file From fea62e963fe61fa487c53025c6b057a966ae4f05 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:04:12 +0200 Subject: [PATCH 04/13] adding more script --- azure-boostrap.yaml | 54 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index e7abbbd..9e5542f 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -64,7 +64,59 @@ jobs: echo "Pool ID: $poolId" # Define the URL to get all agents in the pool - url="https://dev.azure.com/${organization}/_ + 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 displayName: 'Trigger Azure DevOps Pipeline' env: AZURE_DEVOPS_ORG: nanoFramework From 4ccbf0838344099d79db11c9cf4d57e3b43f3cdd Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:06:16 +0200 Subject: [PATCH 05/13] fixing build as env --- azure-boostrap.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 9e5542f..75bf96b 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -45,7 +45,7 @@ jobs: project="${AZURE_DEVOPS_PROJECT}" pipelineId="${AZURE_DEVOPS_PIPELINE_ID}" poolName="${AZURE_POOL_NAME}" - branch="refs/heads/${{ Build.SourceBranchName }}" + branch="refs/heads/${BUILD_SOURCEBRANCHNAME}" # Encode the PAT patEncoded=$(echo -n ":${{ AZURE_DEVOPS_PAT }}" | base64) @@ -123,4 +123,5 @@ jobs: AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream AZURE_DEVOPS_PIPELINE_ID: 111 AZURE_POOL_NAME: TestStream - AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) \ No newline at end of file + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) + BUILD_SOURCEBRANCHNAME: ${{ Build.SourceBranchName }} \ No newline at end of file From c186873e2a3e5bc692991f67f1c650c8026b7960 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:07:31 +0200 Subject: [PATCH 06/13] fixing pat env --- azure-boostrap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 75bf96b..dfcd9b7 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -48,7 +48,7 @@ jobs: branch="refs/heads/${BUILD_SOURCEBRANCHNAME}" # Encode the PAT - patEncoded=$(echo -n ":${{ AZURE_DEVOPS_PAT }}" | base64) + patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64) # Define the headers headers=( From 81baca748ce4d5bab776aa50faab508de507aa8f Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:09:28 +0200 Subject: [PATCH 07/13] fixing build source name --- azure-boostrap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index dfcd9b7..7a467ed 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -124,4 +124,4 @@ jobs: AZURE_DEVOPS_PIPELINE_ID: 111 AZURE_POOL_NAME: TestStream AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - BUILD_SOURCEBRANCHNAME: ${{ Build.SourceBranchName }} \ No newline at end of file + BUILD_SOURCEBRANCHNAME: $(Build.SourceBranchName) \ No newline at end of file From d90fbf84bf0e736a89c8fca18f136b893c399ce7 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:12:47 +0200 Subject: [PATCH 08/13] changing for build source branch --- azure-boostrap.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 7a467ed..46e22c0 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -45,7 +45,7 @@ jobs: project="${AZURE_DEVOPS_PROJECT}" pipelineId="${AZURE_DEVOPS_PIPELINE_ID}" poolName="${AZURE_POOL_NAME}" - branch="refs/heads/${BUILD_SOURCEBRANCHNAME}" + branch="${BUILD_SOURCEBRANCHNAME}" # Encode the PAT patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64) @@ -124,4 +124,4 @@ jobs: AZURE_DEVOPS_PIPELINE_ID: 111 AZURE_POOL_NAME: TestStream AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - BUILD_SOURCEBRANCHNAME: $(Build.SourceBranchName) \ No newline at end of file + BUILD_SOURCEBRANCHNAME: $(Build.SourceBranch) \ No newline at end of file From 6ce03ffaa8f6a78c641948f68fdc59c05b6ce640 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:19:27 +0200 Subject: [PATCH 09/13] re,aming --- azure-boostrap.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 46e22c0..052d415 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -45,7 +45,7 @@ jobs: project="${AZURE_DEVOPS_PROJECT}" pipelineId="${AZURE_DEVOPS_PIPELINE_ID}" poolName="${AZURE_POOL_NAME}" - branch="${BUILD_SOURCEBRANCHNAME}" + branch="${BUILD_SOURCEBRANCH}" # Encode the PAT patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64) @@ -124,4 +124,4 @@ jobs: AZURE_DEVOPS_PIPELINE_ID: 111 AZURE_POOL_NAME: TestStream AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - BUILD_SOURCEBRANCHNAME: $(Build.SourceBranch) \ No newline at end of file + BUILD_SOURCEBRANCH: $(Build.SourceBranch) \ No newline at end of file From b06560f7996375757a220b70f878dcd1d01a67ae Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:22:48 +0200 Subject: [PATCH 10/13] removing non needed elements from the action --- .github/workflows/build.yml | 94 ------------------------------------- 1 file changed, 94 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1f94a1..54f9638 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,98 +20,4 @@ jobs: - 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 \ No newline at end of file From 8c28a91f7c763d911aa046beb76e1aea341246d4 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:35:58 +0200 Subject: [PATCH 11/13] adjusting pipeline to test --- azure-boostrap.yaml | 53 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 052d415..5e14650 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -30,6 +30,13 @@ jobs: pool: vmImage: 'ubuntu-latest' + variables: + AZURE_DEVOPS_ORG: nanoFramework + AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream + AZURE_DEVOPS_PIPELINE_ID: 111 + AZURE_POOL_NAME: TestStream + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) + steps: - script: | # Validate required environment variables @@ -112,6 +119,7 @@ jobs: if [ $http_code -eq 200 ]; then run_id=$(echo "$content" | jq -r '.id') echo "Pipeline triggered successfully. Run ID: $run_id" + echo "##vso[task.setvariable variable=run_id]$run_id" else echo "Failed to trigger pipeline. HTTP Status Code: $http_code" echo "Response: $content" @@ -119,9 +127,42 @@ jobs: fi displayName: 'Trigger Azure DevOps Pipeline' env: - AZURE_DEVOPS_ORG: nanoFramework - AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream - AZURE_DEVOPS_PIPELINE_ID: 111 - AZURE_POOL_NAME: TestStream - AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - BUILD_SOURCEBRANCH: $(Build.SourceBranch) \ No newline at end of file + BUILD_SOURCEBRANCH: $(Build.SourceBranch) + + - script: | + echo "Pipeline to monitor Run ID: $(run_id)" + # Define the URL to get the pipeline run status + url="https://dev.azure.com/${AZURE_DEVOPS_ORG}/${AZURE_DEVOPS_PROJECT}/_apis/pipelines/${AZURE_DEVOPS_PIPELINE_ID}/runs/$(run_id)?api-version=7.1" + + # Loop to monitor the pipeline run status + while true; do + response=$(curl -s -w "%{http_code}" -H "Authorization: Basic $(echo -n ":${AZURE_DEVOPS_PAT}" | base64)" -X GET "$url") + http_code=${response: -3} + content=${response::-3} + + if [ $http_code -eq 200 ]; then + state=$(echo "$content" | jq -r '.state') + result=$(echo "$content" | jq -r '.result') + + echo "Pipeline run state: $state" + + if [ "$state" == "completed" ]; then + echo "Pipeline run completed with result: $result" + if [ "$result" == "succeeded" ]; then + exit 0 + else + exit 1 + fi + fi + else + echo "Failed to get pipeline run status. HTTP Status Code: $http_code" + echo "Response: $content" + exit 1 + fi + + # Wait for a while before checking again + sleep 30 + done + displayName: 'Monitoring Azure DevOps pipeline' + env: + run_id: $(run_id) \ No newline at end of file From 68f61644c244eeb8904a235f3a3bf54807b20cc3 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 15:42:41 +0200 Subject: [PATCH 12/13] moving pat around --- azure-boostrap.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azure-boostrap.yaml b/azure-boostrap.yaml index 5e14650..3ca272d 100644 --- a/azure-boostrap.yaml +++ b/azure-boostrap.yaml @@ -34,8 +34,7 @@ jobs: AZURE_DEVOPS_ORG: nanoFramework AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream AZURE_DEVOPS_PIPELINE_ID: 111 - AZURE_POOL_NAME: TestStream - AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) + AZURE_POOL_NAME: TestStream steps: - script: | @@ -128,6 +127,7 @@ jobs: displayName: 'Trigger Azure DevOps Pipeline' env: BUILD_SOURCEBRANCH: $(Build.SourceBranch) + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) - script: | echo "Pipeline to monitor Run ID: $(run_id)" @@ -165,4 +165,5 @@ jobs: done displayName: 'Monitoring Azure DevOps pipeline' env: - run_id: $(run_id) \ No newline at end of file + run_id: $(run_id) + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) \ No newline at end of file From 7e2e2781cd324c01a4b22af94d705abd06ca87d1 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 22 Oct 2024 16:20:27 +0200 Subject: [PATCH 13/13] adjusting maintainer documentation --- maintainer.md | 275 +++++++++++++++++++++++++++++++------------------- 1 file changed, 171 insertions(+), 104 deletions(-) diff --git a/maintainer.md b/maintainer.md index 54d3328..c7f9479 100644 --- a/maintainer.md +++ b/maintainer.md @@ -65,6 +65,7 @@ Remove the trigger part and replace with, remove the cancel part as well: # The Pipeline is going to be called by the GitHub action. # Manual trigger is always possible. trigger: none +pr: none ``` Add the folling block after the `resources` entry: @@ -75,8 +76,7 @@ parameters: displayName: List of capabilities to run the tests on type: object default: - - XIAO_ESP32C3 - - ESP32_C3_REV3 + - none ``` > [!Important] @@ -124,116 +124,180 @@ Add then this block at the very end, it will create multi stages that depends on > [!Important] > You have to list all the tests you want to run with each individual tests you want to run. Each line is a specific dll, separate the runsetting with the built dll with a coma. -## Creating a GitHub Action to trigger the pipeline +## Creating a new ADO pipeline to trigger the pipeline -You will have to add a GitHub action in `.github\workflows` folders. You can name the file `build.yml`. And place the following content: +You will have to add a new ADO pipeline. You can name the file `azure-bootstrap.yml`. And place the following content: ```yaml -name: Trigger build pipeline +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. -on: - pull_request: - branches: +trigger: + branches: + include: - main + - develop + - release-* + paths: + exclude: + - .github_changelog_generator + - .gitignore + - CHANGELOG.md + - CODE_OF_CONDUCT.md + - LICENSE.md + - README.md + - NuGet.Config + - assets/* + - config/* + - .github/* + +# PR always trigger build +pr: + autoCancel: true jobs: - build: - runs-on: ubuntu-latest - - steps: - - 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 - } +- job: Trigger + displayName: Trigger Azure Dev Ops build and test pipeline + pool: + vmImage: 'ubuntu-latest' + + variables: + AZURE_DEVOPS_ORG: nanoFramework + AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream + AZURE_DEVOPS_PIPELINE_ID: 111 + AZURE_POOL_NAME: TestStream + + steps: + - script: | + # Validate required environment variables + for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME; 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="${BUILD_SOURCEBRANCH}" + + # Encode the PAT + patEncoded=$(echo -n ":${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 + } + }, + 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" + echo "##vso[task.setvariable variable=run_id]$run_id" + else + echo "Failed to trigger pipeline. HTTP Status Code: $http_code" + echo "Response: $content" + exit 1 + fi + displayName: 'Trigger Azure DevOps Pipeline' + env: + BUILD_SOURCEBRANCH: $(Build.SourceBranch) + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) + + - script: | + echo "Pipeline to monitor Run ID: $(run_id)" + # Define the URL to get the pipeline run status + url="https://dev.azure.com/${AZURE_DEVOPS_ORG}/${AZURE_DEVOPS_PROJECT}/_apis/pipelines/${AZURE_DEVOPS_PIPELINE_ID}/runs/$(run_id)?api-version=7.1" + + # Loop to monitor the pipeline run status + while true; do + response=$(curl -s -w "%{http_code}" -H "Authorization: Basic $(echo -n ":${AZURE_DEVOPS_PAT}" | base64)" -X GET "$url") + http_code=${response: -3} + content=${response::-3} + + if [ $http_code -eq 200 ]; then + state=$(echo "$content" | jq -r '.state') + result=$(echo "$content" | jq -r '.result') + + echo "Pipeline run state: $state" + + if [ "$state" == "completed" ]; then + echo "Pipeline run completed with result: $result" + if [ "$result" == "succeeded" ]; then + exit 0 + else + exit 1 + fi + fi + else + echo "Failed to get pipeline run status. HTTP Status Code: $http_code" + echo "Response: $content" + exit 1 + fi + + # Wait for a while before checking again + sleep 30 + done + displayName: 'Monitoring Azure DevOps pipeline' + env: + run_id: $(run_id) + AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) ``` You will have to adjust the following to match the ADO project name and pipeline ID: @@ -242,3 +306,6 @@ You will have to adjust the following to match the ADO project name and pipeline AZURE_DEVOPS_PROJECT: nanoFramework.IoT.TestStream AZURE_DEVOPS_PIPELINE_ID: 111 ``` + +> [!Important] +> You **must** add a secret with the PAT token to the ADO pipeline. Make sure to check that it is a **secret**.