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