@@ -10,157 +10,33 @@ trigger:
1010 paths :
1111 exclude :
1212 - .gitignore
13- - CHANGELOG.md
13+ - .editorconfig
14+ - spelling_exclusion.dic
1415 - LICENSE.md
1516 - README.md
16- - NuGet.Config
1717 - assets/*
1818 - .github/*
1919
2020# PR always trigger build
2121pr :
2222 autoCancel : true
2323
24+ # add nf-tools repo to resources (for Azure Pipelines templates)
25+ resources :
26+ repositories :
27+ - repository : templates
28+ type : github
29+ name : nanoframework/nf-tools
30+ endpoint : nanoframework
31+
2432jobs :
2533- job : Trigger
2634 displayName : Trigger Azure Dev Ops build and test pipeline
2735 pool :
2836 vmImage : ' ubuntu-latest'
2937
30- variables :
31- AZURE_DEVOPS_ORG : nanoFramework
32- AZURE_DEVOPS_PROJECT : nanoFramework.Protobuf
33- AZURE_DEVOPS_PIPELINE_ID : 117
34- AZURE_POOL_NAME : TestStream
35-
36- steps :
37- - script : |
38- # Validate required environment variables
39- for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME; do
40- if [ -z "${!var}" ]; then
41- echo "Error: Required environment variable $var is not set"
42- exit 1
43- fi
44- done
45-
46- # Define the Azure DevOps organization, project, and pipeline
47- organization="${AZURE_DEVOPS_ORG}"
48- project="${AZURE_DEVOPS_PROJECT}"
49- pipelineId="${AZURE_DEVOPS_PIPELINE_ID}"
50- poolName="${AZURE_POOL_NAME}"
51- branch="${BUILD_SOURCEBRANCH}"
52-
53- # Encode the PAT
54- patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64)
55-
56- # Define the headers
57- headers=(
58- -H "Authorization: Basic $patEncoded"
59- -H "Content-Type: application/json"
60- )
61-
62- # Get the pool ID
63- url="https://dev.azure.com/${organization}/_apis/distributedtask/pools?poolName=${poolName}&api-version=7.1"
64- AZP_POOL_AGENTS=$(curl -s "${headers[@]}" -X GET "$url")
65- poolId=$(echo "$AZP_POOL_AGENTS" | jq -r '.value[0].id')
66-
67- echo "Pool ID: $poolId"
68-
69- # Define the URL to get all agents in the pool
70- url="https://dev.azure.com/${organization}/_apis/distributedtask/pools/${poolId}/agents?includeCapabilities=true&api-version=7.1"
71-
72- response=$(curl -s -w "%{http_code}" "${headers[@]}" -X GET "$url")
73- http_code=${response: -3}
74- content=${response::-3}
75-
76- if [ $http_code -eq 200 ]; then
77- # Extract all userCapabilities names for online and enabled agents as a unique list
78- capabilityNames=$(echo "$content" | jq -r '[.value[] | select(.status == "online" and .enabled == true) | .userCapabilities | keys] | unique | flatten | join("\n- ")')
79- else
80- echo "Failed to retrieve agent capabilities. HTTP Status Code: $http_code"
81- echo "Response: \"$content\""
82- exit 1
83- fi
84- echo "Unique userCapabilities names: \"$capabilityNames\""
85-
86- # Prepare the parameters
87- parametersJson=$(jq -n --arg appComponents "- $capabilityNames" '{templateParameters: {appComponents: $appComponents}}')
88-
89- echo "Parameters: \"$parametersJson\""
90- echo "Branch for PR: \"$branch\""
91-
92- # Define the request body
93- bodyJson=$(jq -n --argjson parameters "$parametersJson" --arg branch "$branch" '{
94- resources: {
95- repositories:
96- {
97- self: {
98- refName: $branch
99- }
100- }
101- },
102- templateParameters: $parameters.templateParameters
103- }')
104-
105- echo "Request body: \"$bodyJson\""
106-
107- # Define the URL
108- url="https://dev.azure.com/${organization}/${project}/_apis/pipelines/${pipelineId}/runs?api-version=7.1"
109-
110- # Trigger the pipeline
111- response=$(curl -s -w "%{http_code}" "${headers[@]}" -X POST -d "$bodyJson" "$url")
112- http_code=${response: -3}
113- content=${response::-3}
114-
115- if [ $http_code -eq 200 ]; then
116- run_id=$(echo "$content" | jq -r '.id')
117- echo "Pipeline triggered successfully. Run ID: $run_id"
118- echo "##vso[task.setvariable variable=run_id]$run_id"
119- else
120- echo "Failed to trigger pipeline. HTTP Status Code: $http_code"
121- echo "Response: $content"
122- exit 1
123- fi
124- displayName: 'Trigger Azure DevOps Pipeline'
125- env:
126- BUILD_SOURCEBRANCH: $(Build.SourceBranch)
127- AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT)
128-
129- - script : |
130- echo "Pipeline to monitor Run ID: $(run_id)"
131- # Define the URL to get the pipeline run status
132- url="https://dev.azure.com/${AZURE_DEVOPS_ORG}/${AZURE_DEVOPS_PROJECT}/_apis/pipelines/${AZURE_DEVOPS_PIPELINE_ID}/runs/$(run_id)?api-version=7.1"
133-
134- # Loop to monitor the pipeline run status
135- while true; do
136- response=$(curl -s -w "%{http_code}" -H "Authorization: Basic $(echo -n ":${AZURE_DEVOPS_PAT}" | base64)" -X GET "$url")
137- http_code=${response: -3}
138- content=${response::-3}
139-
140- if [ $http_code -eq 200 ]; then
141- state=$(echo "$content" | jq -r '.state')
142- result=$(echo "$content" | jq -r '.result')
143-
144- echo "Pipeline run state: $state"
145-
146- if [ "$state" == "completed" ]; then
147- echo "Pipeline run completed with result: $result"
148- if [ "$result" == "succeeded" ]; then
149- exit 0
150- else
151- exit 1
152- fi
153- fi
154- else
155- echo "Failed to get pipeline run status. HTTP Status Code: $http_code"
156- echo "Response: $content"
157- exit 1
158- fi
159-
160- # Wait for a while before checking again
161- sleep 30
162- done
163- displayName: 'Monitoring Azure DevOps pipeline'
164- env:
165- run_id: $(run_id)
166- AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT)
38+ steps :
39+ - template : azure-pipelines-templates/device-bootstrap.yml@templates
40+ parameters :
41+ AZURE_DEVOPS_PROJECT : nanoFramework.Protobuf
42+ AZURE_DEVOPS_PIPELINE_ID : 117
0 commit comments