@@ -18,7 +18,11 @@ steps:
1818 echo >&2 "##vso[task.setvariable variable=ACNCI_BUILD_SP_APP_OID;isoutput=true;]$SP_APP_OID"
1919 # Get Subscription ID.
2020 SUBSCRIPTION_ID=$(az account show | jq -rc '.id')
21+ SUBSCRIPTION_NAME=$(az account show | jq -rc '.name')
22+ TENANT_ID=$(az account show | jq -rc '.tenantId')
2123 echo >&2 "##vso[task.setvariable variable=ACNCI_BUILD_SUBSCRIPTION_ID;isoutput=true;issecret=true]$SUBSCRIPTION_ID"
24+ echo >&2 "##vso[task.setvariable variable=ACNCI_BUILD_SUBSCRIPTION_NAME;isoutput=true;issecret=true]$SUBSCRIPTION_NAME"
25+ echo >&2 "##vso[task.setvariable variable=ACNCI_BUILD_TENANTID;isoutput=true;issecret=true]$TENANT_ID"
2226
2327
2428# # Resource Groups ##
@@ -142,6 +146,78 @@ steps:
142146 MI_LIST : $(OUT_RESULT)
143147 MI_LIST_LENGTH : $(OUT_RESULT_LENGTH)
144148
149+ # # MI Service Connection
150+
151+ - template : get-resources.steps.yaml
152+ parameters :
153+ resourceType : serviceconnection
154+ serviceConnection : $(ACN_TEST_SERVICE_CONNECTION)
155+ inputs :
156+ resourceGroupName : $(resourcegroups.ACNCI_BUILD_RESOURCEGROUP)
157+ buildTagDefinitionIdKey : $(ACNCI_BUILDTAG_DEFINITIONID)
158+ buildTagCreatedByAppIdKey : $(ACNCI_BUILDTAG_CREATEDBYAPPID)
159+ # SERVICECONNECTION_PRINCIPALID: ${{ parameters.inputs.serviceConnectionPrincipalId }}
160+ # SUBSCRIPTION_ID: ${{ parameters.inputs.subscriptionId }}
161+ # SUBSCRIPTION_NAME: ${{ parameters.inputs.subscriptionName }}
162+ # SERVICECONNECTION_TENANTID: ${{ parameters.inputs.tenantId }}
163+ # SERVICECONNECTION_NAME: ${{ parameters.inputs.serviceConnectionName }}
164+
165+ - template : create-or-update-resource.steps.yaml
166+ parameters :
167+ resourceType : serviceconnection
168+ serviceConnection : $(ACN_TEST_SERVICE_CONNECTION)
169+ createCondition : |
170+ and(succeeded(),
171+ or(not(variables.OUT_RESULT_LENGTH),
172+ eq(variables.OUT_RESULT_LENGTH, 'null'),
173+ lt(variables.OUT_RESULT_LENGTH, 1)))
174+ updateCondition : False
175+ inputs :
176+ serviceConnectionName : $(managedidentity.ACNCI_MANAGEDIDENTITY_NAME)-serviceconnection
177+ serviceConnectionPrincipalId : $(managedidentity.ACNCI_MANAGEDIDENTITY_OBJECTID)
178+ subscriptionId : $(build.ACNCI_BUILD_SUBSCRIPTION_ID)
179+ subscriptionName : $(build.ACNCI_BUILD_SUBSCRIPTION_NAME)
180+ tenantId : $(build.ACNCI_BUILD_TENANT_ID)
181+ buildTagDefinitionIdKey : $(ACNCI_BUILDTAG_DEFINITIONID)
182+ buildTagCreatedByAppIdKey : $(ACNCI_BUILDTAG_CREATEDBYAPPID)
183+ buildTagCreatedByBuildIdKey : $(ACNCI_BUILDTAG_CREATEDBYBUILDID)
184+
185+ - task : AzureCLI@2
186+ name : managedidentity
187+ displayName : " [Output] Build User ServiceConnection Details"
188+ inputs :
189+ azureSubscription : $(ACN_TEST_SERVICE_CONNECTION)
190+ scriptType : bash
191+ scriptLocation : inlineScript
192+ addSpnToEnvironment : true
193+ inlineScript : |
194+ set -e
195+ [[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
196+
197+ # Select MI to use
198+ RANDOM_SELECT=`tr -dc '1-9' < /dev/urandom | head -c${1:-7}`
199+ IDX=$(( "$RANDOM_SELECT" % "$SC_LIST_LENGTH" ))
200+ SC_DATA=$(echo "$SC_LIST" | jq --argjson IDX "$IDX" -rc '.[$IDX]')
201+
202+ echo "$SC_DATA"
203+ exit 1
204+ SC_ID=$(echo "$SC_DATA" | jq -r '.id')
205+ echo >&2 "##vso[task.setvariable variable=ACNCI_SERVICECONNECTION_ID;isoutput=true]$SC_ID"
206+ SC_PRINCIPALID=$(echo "$SC_DATA" | jq -r '.principalId')
207+ echo >&2 "##vso[task.setvariable variable=ACNCI_SERVICECONNECTION_NAME;isoutput=true]$SC_PRINCIPALID"
208+ SC_APPID=$(echo "$SC_DATA" | jq -r '.clientId')
209+ echo >&2 "##vso[task.setvariable variable=ACNCI_MANAGEDIDENTITY_APPID;isoutput=true]$SC_APPID"
210+ SC_NAME=$(echo "$SC_DATA" | jq -r '.name')
211+ echo >&2 "##vso[task.setvariable variable=ACNCI_MANAGEDIDENTITY_NAME;isoutput=true]$SC_NAME"
212+ env :
213+ SC_LIST : $(OUT_RESULT)
214+ SC_LIST_LENGTH : $(OUT_RESULT_LENGTH)
215+
216+ # SERVICECONNECTION_PRINCIPALID: ${{ parameters.inputs.serviceConnectionPrincipalId }}
217+ # SUBSCRIPTION_ID: ${{ parameters.inputs.subscriptionId }}
218+ # SUBSCRIPTION_NAME: ${{ parameters.inputs.subscriptionName }}
219+ # SERVICECONNECTION_TENANTID: ${{ parameters.inputs.tenantId }}
220+ # SERVICECONNECTION_NAME: ${{ parameters.inputs.serviceConnectionName }}
145221
146222# # MI Role Definition ##
147223
@@ -297,7 +373,6 @@ steps:
297373- task : AzureCLI@2
298374 name : build_storage
299375 displayName : " [Provision] Establish Build Storage"
300- condition : not(or(failed(), skipped()))
301376 inputs :
302377 azureSubscription : $(ACN_TEST_SERVICE_CONNECTION)
303378 scriptType : bash
0 commit comments