Skip to content

Commit 12c74d9

Browse files
author
Sheyla Trudo
committed
fixup! Move to Resource Module
1 parent 1362ee1 commit 12c74d9

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

.pipelines/templates/artifact-storage.steps.yaml

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ steps:
259259
R_INDEX=$(( "$SA_RANDOM_SELECT" % "$SA_LIST_LENGTH" ))
260260
# Make a random selection from the pool
261261
SA_DATA=$(echo "$SA_LIST" | jq --argjson IDX "$R_INDEX" -rc '.[$IDX]')
262-
echo "Delete me"
263-
echo "$SA_DATA"
264262
if (( "$SA_LIST_LENGTH" > 0 )); then
265263
# Azure Resource ID
266264
SA_ID=$(echo "$SA_DATA" | jq -r '.id')
@@ -279,6 +277,9 @@ steps:
279277
# Storage Account Location
280278
SA_LOCATION=$(echo "$SA_DATA" | jq -r '.location')
281279
echo >&2 "##vso[task.setvariable variable=ACNCI_STORAGEACCOUNT_LOCATION;isoutput=true]$SA_LOCATION"
280+
# Current Build Storage Data
281+
echo >&2 "##vso[task.setvariable variable=ACNCI_STORAGEACCOUNT_CONTAINER_NAME;isoutput=true]$STORAGECONTAINER_NAME"
282+
echo >&2 "##vso[task.setvariable variable=ACNCI_STORAGEACCOUNT_BLOB_PATH;isoutput=true]$STORAGEBLOB_PATH"
282283
# - Local Use Only -
283284
# SA Object
284285
echo >&2 "##vso[task.setvariable variable=ACNCI_STORAGEACCOUNT]$SA_DATA"
@@ -290,35 +291,40 @@ steps:
290291
SA_LIST: $(OUT_RESULT)
291292
SA_LIST_LENGTH: $(OUT_RESULT_LENGTH)
292293
SA_SERVICE_CONN: $(ACN_TEST_SERVICE_CONNECTION)
294+
STORAGECONTAINER_NAME: "azure-container-networking-pr"
295+
STORAGEBLOB_PATH: $(Build.BuildId)/$(System.JobAttempt)
293296

294297
- task: AzureCLI@2
295-
name: artifact_container
296-
displayName: "[Output] Ensure Storage Container"
298+
name: build_storage
299+
displayName: "[Provision] Establish Build Storage"
300+
condition: not(or(failed(), skipped()))
297301
inputs:
298302
azureSubscription: $(ACN_TEST_SERVICE_CONNECTION)
299303
scriptType: bash
300304
scriptLocation: inlineScript
301-
addSpnToEnvironment: true
302305
inlineScript: |
303306
set -e
304307
[[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
305308
306-
az storage account show -n "$SA_NAME" --query networkRuleSet
307309
az storage container create \
308-
--account-name "$SA_NAME" \
309-
--resource-group "$RG_NAME" \
310-
--name "$CONTAINER_NAME" \
310+
--account-name "$STORAGEACCOUNT_NAME" \
311+
--resource-group "$RESOURCEGROUP_NAME" \
312+
--name "$STORAGECONTAINER_NAME" \
313+
--auth-mode login || echo >&2 "##[info]Storage container provisioned."
314+
315+
echo "hold" | az storage blob upload \
316+
--data @- \
317+
--name "$STORAGEBLOB_PATH/.created" \
318+
--container-name "$STORAGECONTAINER_NAME" \
319+
--account-name "$STORAGEACCOUNT_NAME" \
311320
--auth-mode login
312-
313-
echo >&2 "##vso[task.setvariable variable=ACNCI_STORAGEACCOUNT_ARTIFACT_CONTAINER;isoutput=true]$CONTAINER_NAME"
314321
env:
315-
CONTAINER_NAME: "azure-container-networking-pr"
316-
RG_NAME: $(resourcegroups.ACNCI_BUILD_RESOURCEGROUP)
317-
SA_NAME: $(artifact_storage.ACNCI_STORAGEACCOUNT_NAME)
318-
ACNCI_MANAGEDIDENTITY_ID: $(managedidentity.ACNCI_MANAGEDIDENTITY_ID)
322+
RESOURCEGROUP_NAME: $(resourcegroups.ACNCI_BUILD_RESOURCEGROUP)
323+
STORAGEACCOUNT_NAME: $(artifact_storage.ACNCI_STORAGEACCOUNT_NAME)
324+
STORAGECONTAINER_NAME: $(artifact_storage.ACNCI_STORAGEACCOUNT_CONTAINER_NAME)
319325

320326
- task: AzureCLI@2
321-
displayName: "[Provision] Container Access Permissions"
327+
displayName: "[Provision] Build User Access Permissions"
322328
continueOnError: true
323329
inputs:
324330
azureSubscription: $(ACN_TEST_SERVICE_CONNECTION)
@@ -331,25 +337,10 @@ steps:
331337
332338
az role assignment create \
333339
--role "Storage Blob Data Contributor" \
334-
--assignee "$ACNCI_MANAGEDIDENTITY_OBJECTID" \
340+
--assignee "$MANAGEDIDENTITY_OBJECTID" \
335341
--assignee-principal-type "ServicePrincipal" \
336-
--scope "$ACNCI_STORAGEACCOUNT_ID"
342+
--scope "$STORAGEACCOUNT_ID/blobServices/default/containers/$STORAGECONTAINER_NAME"
337343
env:
338-
ACNCI_BUILD_RESOURCEGROUP_ID: $(resourcegroups.ACNCI_BUILD_RESOURCEGROUP_ID)
339-
ACNCI_MANAGEDIDENTITY_OBJECTID: $(managedidentity.ACNCI_MANAGEDIDENTITY_OBJECTID)
340-
ACNCI_STORAGEACCOUNT_ID: $(storageaccounts.ACNCI_STORAGEACCOUNT_ID)
341-
342-
- task: AzureCLI@2
343-
name: artifact_blob
344-
displayName: "[Output] Get Blob Path"
345-
# Always run to generate new blob name
346-
condition: always()
347-
inputs:
348-
azureSubscription: $(ACN_TEST_SERVICE_CONNECTION)
349-
scriptType: bash
350-
scriptLocation: inlineScript
351-
inlineScript: |
352-
set -e
353-
[[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
354-
355-
echo >&2 "##vso[task.setvariable variable=ACNCI_STORAGEACCOUNT_BLOBPATH;isoutput=true]$BUILD_BUILDID/$SYSTEM_JOBATTEMPT"
344+
MANAGEDIDENTITY_OBJECTID: $(managedidentity.ACNCI_MANAGEDIDENTITY_OBJECTID)
345+
STORAGEACCOUNT_ID: $(artifact_storage.ACNCI_STORAGEACCOUNT_ID)
346+
STORAGECONTAINER_NAME: $(artifact_storage.ACNCI_STORAGEACCOUNT_CONTAINER_NAME)

0 commit comments

Comments
 (0)