Skip to content

Commit 44446bd

Browse files
authored
Update ML Sample Pipeline to use ARM Service Connection (#36896)
* utilize managed identity w/ service connection instead of static connection string for ml samples artifact upload
1 parent 682d021 commit 44446bd

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

eng/pipelines/templates/jobs/trigger-ml-sample-pipeline.yml renamed to eng/pipelines/trigger-ml-sample-pipeline.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parameters:
44
default: 'ml'
55
- name: Artifacts
66
type: object
7-
default:
7+
default:
88
- name: azure-ai-ml
99
safeName: azureaiml
1010
skipVerifyChangeLog: true
@@ -17,7 +17,9 @@ jobs:
1717
displayName: "Build, Upload, and PR Azure ML Changeset"
1818
timeoutInMinutes: 90
1919
variables:
20-
- template: ../variables/globals.yml
20+
- name: StorageAccountName
21+
value: 'docsupport'
22+
- template: /eng/pipelines/templates/variables/globals.yml
2123

2224
pool:
2325
name: azsdk-pool-mms-ubuntu-2004-general
@@ -39,9 +41,9 @@ jobs:
3941
versionSpec: $(PythonVersion)
4042

4143
- script: |
42-
python -m pip install setuptools==58.3.0
43-
python -m pip install -r eng/ci_tools.txt
44-
python -m pip install -r eng/ml_sample_tools.txt
44+
python -m pip install tools/azure-sdk-tools[build]
45+
python -m pip install azure-identity
46+
python -m pip install azure-storage-blob
4547
displayName: 'Prep Environment'
4648
4749
- pwsh: |
@@ -61,20 +63,24 @@ jobs:
6163
Get-ChildItem "$(mlrepo)" -R
6264
displayName: Output Staging Directory
6365
64-
- task: PythonScript@0
65-
displayName: 'Generate Samples Repo Changes'
66-
env:
67-
BLOB_CONNECTION_STRING: $(azure-sdk-docsupport-cs)
66+
- pwsh: |
67+
cat "$(mlrepo)/sdk/python/setup.sh"
68+
displayName: Display setup.sh pre-update
69+
70+
- task: AzurePowerShell@5
71+
displayName: Generate Samples Repo Changes
6872
inputs:
69-
scriptPath: 'scripts/devops_tasks/generate_ml_sample_update.py'
70-
arguments: >-
71-
--ml-repo="$(mlrepo)"
72-
--ml-wheel-folder="$(Build.ArtifactStagingDirectory)/azure-ai-ml"
73-
--build-id="$(Build.BuildId)"
73+
azureSubscription: 'Azure SDK Artifacts'
74+
azurePowerShellVersion: LatestVersion
75+
pwsh: true
76+
ScriptType: InlineScript
77+
Inline: |
78+
python scripts/devops_tasks/generate_ml_sample_update.py --ml-repo "$(mlrepo)" --ml-wheel-folder "$(Build.ArtifactStagingDirectory)/azure-ai-ml" --build-id "$(Build.BuildId)" --storage-account-name "$(StorageAccountName)";
79+
exit $LASTEXITCODE;
7480
7581
- pwsh: |
7682
cat "$(mlrepo)/sdk/python/setup.sh"
77-
displayName: Display Updated setup.sh
83+
displayName: Display setup.sh post-update
7884
7985
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
8086
parameters:

scripts/devops_tasks/generate_ml_sample_update.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66

77
from azure.storage.blob import BlobServiceClient
8+
from azure.identity import AzurePowerShellCredential, ChainedTokenCredential, AzureCliCredential
89

910
UPLOAD_PATTERN = "{build_id}/{filename}"
1011
DEFAULT_CONTAINER = os.getenv("BLOB_CONTAINER", "ml-sample-submissions")
@@ -59,14 +60,23 @@ def replace_test_install_command(content, targeted_urls):
5960
help=("The folder from where the the azure ml wheel will reside."),
6061
)
6162

63+
parser.add_argument(
64+
"--storage-account-name",
65+
dest="storage_account_name",
66+
help=("The name of the storage account"),
67+
)
68+
69+
6270
args = parser.parse_args()
6371

6472
print("Input repo {}".format(args.ml_root))
6573
print("Folder for search {}".format(args.wheel_folder))
6674

6775
target_glob = os.path.join(os.path.abspath(args.wheel_folder), "*.whl")
6876
sdk_setup_sh = os.path.join(os.path.abspath(args.ml_root), "sdk", "python", "setup.sh")
69-
blob_service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING)
77+
credential_chain = ChainedTokenCredential(AzureCliCredential(), AzurePowerShellCredential())
78+
79+
blob_service_client = BlobServiceClient(account_url=f"https://{args.storage_account_name}.blob.core.windows.net", credential=credential_chain)
7080
container_client = blob_service_client.get_container_client(DEFAULT_CONTAINER)
7181
to_be_installed = []
7282

0 commit comments

Comments
 (0)