@@ -18,10 +18,9 @@ parameters:
1818 default : TestStream
1919
2020steps :
21- # need this here in order to persist GitHub credentials
2221 - checkout : self
23- submodules : true
24- fetchDepth : 0
22+ clean : true
23+ fetchDepth : 1
2524
2625 - script : |
2726 # Validate required environment variables
@@ -39,8 +38,49 @@ steps:
3938 poolName="${{ parameters.AZURE_POOL_NAME }}"
4039 branch="${BUILD_SOURCEBRANCH}"
4140
42- # fix the branch name to trigger PR build
41+ # Replace 'merge' with 'head' in the $branch variable
4342 branch=$(echo "$branch" | sed 's/merge/head/')
43+ echo "Updated branch: $branch"
44+
45+ # Fetch the PR details from GitHub to get the title
46+ # Extract the PR ID from the branch name
47+ auth=$(echo -n ":$GITHUBTOKEN" | base64)
48+ auth="basic $auth"
49+
50+ prUrl="https://api.github.com/repos/$BUILD_REPOSITORY_NAME/pulls/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
51+ response=$(curl -s -w "%{http_code}" -H "Authorization: $auth" -X GET "$prUrl")
52+ http_code=${response: -3}
53+ content=${response::-3}
54+
55+ if [ $http_code -eq 200 ]; then
56+ prDescription=$(echo "$content" | jq -r '.body')
57+ if [ "$prDescription" = "null" ]; then
58+ echo "Error: Failed to extract PR description from response"
59+ exit 1
60+ fi
61+ else
62+ echo "Error: Failed to fetch PR details. Status code: $http_code"
63+ echo "Response: $content"
64+ exit 1
65+ fi
66+
67+ echo "PR description: $prDescription"
68+
69+ # Get the PR creator
70+ prCreator=$(echo "$content" | jq -r '.user.login')
71+
72+ echo "PR Creator: $prCreator"
73+
74+ # Check if the PR creator is nfbot AND description includes the version update tag,
75+ # and set skipHardwareTest accordingly
76+ # This is to skip the hardware test for update PRs created by nfbot
77+ if [ "$prCreator" == "nfbot" ] && [[ "$prDescription" == "[version update]"* ]]; then
78+ skipHardwareTest=true
79+ else
80+ skipHardwareTest=false
81+ fi
82+
83+ echo "Skip Hardware Test: $skipHardwareTest"
4484
4585 # Encode the PAT
4686 patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64)
@@ -51,29 +91,34 @@ steps:
5191 -H "Content-Type: application/json"
5292 )
5393
54- # Get the pool ID
55- url="https://dev.azure.com/${organization}/_apis/distributedtask/pools?poolName=${poolName}&api-version=7.1"
56- AZP_POOL_AGENTS=$(curl -s "${headers[@]}" -X GET "$url")
57- poolId=$(echo "$AZP_POOL_AGENTS" | jq -r '.value[0].id')
58-
59- echo "Pool ID: $poolId"
60-
61- # Define the URL to get all agents in the pool
62- url="https://dev.azure.com/${organization}/_apis/distributedtask/pools/${poolId}/agents?includeCapabilities=true&api-version=7.1"
63-
64- response=$(curl -s -w "%{http_code}" "${headers[@]}" -X GET "$url")
65- http_code=${response: -3}
66- content=${response::-3}
67-
68- if [ $http_code -eq 200 ]; then
69- # Extract all userCapabilities names for online and enabled agents as a unique list
70- capabilityNames=$(echo "$content" | jq -r '[.value[] | select(.status == "online" and .enabled == true) | .userCapabilities | keys] | unique | flatten | join("\n- ")')
94+ if [ "$skipHardwareTest" = "true" ]; then
95+ # Set the capabilityNames to none
96+ capabilityNames="none"
7197 else
72- echo "Failed to retrieve agent capabilities. HTTP Status Code: $http_code"
73- echo "Response: \"$content\""
74- exit 1
98+ # Get the pool ID
99+ url="https://dev.azure.com/${organization}/_apis/distributedtask/pools?poolName=${poolName}&api-version=7.1"
100+ AZP_POOL_AGENTS=$(curl -s "${headers[@]}" -X GET "$url")
101+ poolId=$(echo "$AZP_POOL_AGENTS" | jq -r '.value[0].id')
102+
103+ echo "Pool ID: $poolId"
104+
105+ # Define the URL to get all agents in the pool
106+ url="https://dev.azure.com/${organization}/_apis/distributedtask/pools/${poolId}/agents?includeCapabilities=true&api-version=7.1"
107+
108+ response=$(curl -s -w "%{http_code}" "${headers[@]}" -X GET "$url")
109+ http_code=${response: -3}
110+ content=${response::-3}
111+
112+ if [ $http_code -eq 200 ]; then
113+ # Extract all userCapabilities names for online and enabled agents as a unique list
114+ capabilityNames=$(echo "$content" | jq -r '[.value[] | select(.status == "online" and .enabled == true) | .userCapabilities | keys] | unique | flatten | join("\n- ")')
115+ else
116+ echo "Failed to retrieve agent capabilities. HTTP Status Code: $http_code"
117+ echo "Response: \"$content\""
118+ exit 1
119+ fi
120+ echo "Unique userCapabilities names: \"$capabilityNames\""
75121 fi
76- echo "Unique userCapabilities names: \"$capabilityNames\""
77122
78123 # Prepare the parameters
79124 parametersJson=$(jq -n --arg appComponents "- $capabilityNames" '{templateParameters: {appComponents: $appComponents}}')
@@ -82,14 +127,13 @@ steps:
82127 echo "Branch for PR: \"$branch\""
83128
84129 # Define the request body
85- bodyJson=$(jq -n --argjson parameters "$parametersJson" --arg branch "$branch" '{
130+ bodyJson=$(jq -n --argjson parameters "$parametersJson" --arg branch "$branch" --arg prTitle "$prTitle" '{
86131 resources: {
87- repositories:
88- {
89- self: {
90- refName: $branch
91- }
132+ repositories: {
133+ self: {
134+ refName: $branch
92135 }
136+ }
93137 },
94138 templateParameters: $parameters.templateParameters
95139 }')
0 commit comments