From 799cee6a005155cfb953f825213a1c638fbb3c60 Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:41:30 +0100 Subject: [PATCH 1/7] Get AzDO token [skip ci] --- get-azdo-token.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 get-azdo-token.yml diff --git a/get-azdo-token.yml b/get-azdo-token.yml new file mode 100644 index 00000000..edc14a40 --- /dev/null +++ b/get-azdo-token.yml @@ -0,0 +1,18 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +pool: + vmImage: windows-latest + +steps: +- task: PowerShell@2 + inputs: + azureDevOpsServiceConnection: 'praval' + targetType: 'inline' + script: | + $token = Get-AzDoToken From 598f9dd83517c9913e292bd60482547dcd03cf5e Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:46:57 +0100 Subject: [PATCH 2/7] Update get-azdo-token.yml for Azure Pipelines --- get-azdo-token.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/get-azdo-token.yml b/get-azdo-token.yml index edc14a40..adb769aa 100644 --- a/get-azdo-token.yml +++ b/get-azdo-token.yml @@ -1,11 +1,9 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- main - +parameters: +- name: azureDevOpsServiceConnection + displayName: Azure DevOps Service Connection + type: string + default: my-azure-subscription + pool: vmImage: windows-latest From 41da2995ecc766f0d11b9d35f4e87f68d8e8e9da Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:49:26 +0100 Subject: [PATCH 3/7] Update get-azdo-token.yml for Azure Pipelines --- get-azdo-token.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get-azdo-token.yml b/get-azdo-token.yml index adb769aa..5c1dae68 100644 --- a/get-azdo-token.yml +++ b/get-azdo-token.yml @@ -2,7 +2,7 @@ parameters: - name: azureDevOpsServiceConnection displayName: Azure DevOps Service Connection type: string - default: my-azure-subscription + default: my-azdo-connection pool: vmImage: windows-latest @@ -10,7 +10,7 @@ pool: steps: - task: PowerShell@2 inputs: - azureDevOpsServiceConnection: 'praval' + azureDevOpsServiceConnection: '${{ parameters.azureDevOpsServiceConnection }}' targetType: 'inline' script: | $token = Get-AzDoToken From 1cba3d6bcbf5b640b90801a116ec92644bf79474 Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:52:27 +0100 Subject: [PATCH 4/7] Update get-azdo-token.yml for Azure Pipelines --- get-azdo-token.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/get-azdo-token.yml b/get-azdo-token.yml index 5c1dae68..0061f922 100644 --- a/get-azdo-token.yml +++ b/get-azdo-token.yml @@ -14,3 +14,16 @@ steps: targetType: 'inline' script: | $token = Get-AzDoToken + + Write-Host "`nUse token with Azure DevOps REST API to list pools in the organization '$(System.CollectionUri)'..." + $apiVersion = "7.1-preview.1" + $apiUrl = "$(System.CollectionUri)_apis/distributedtask/pools?api-version=${apiVersion}" + Invoke-RestMethod -Uri $apiUrl ` + -Headers @{ + Accept = "application/json" + Authorization = "Bearer $token" + "Content-Type" = "application/json" + } ` + -Method Get ` + | Select-Object -ExpandProperty value ` + | Select-Object id, name From 584571776078c63ec0a36d7f3b41bb641256548a Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:55:06 +0100 Subject: [PATCH 5/7] Add Get-AzDoToken to AzDO auth sample --- .../azure-service-connection-azdo-access.yml | 20 +++++++++++++++++++ scripts/azure-devops | 2 +- scripts/identity | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/deployment/azure-service-connection-azdo-access.yml b/deployment/azure-service-connection-azdo-access.yml index 9c253560..6166810e 100644 --- a/deployment/azure-service-connection-azdo-access.yml +++ b/deployment/azure-service-connection-azdo-access.yml @@ -87,3 +87,23 @@ jobs: | Select-Object id, name failOnStandardError: true +- task: PowerShell@2 + displayName: 'Get-AzDoToken' + inputs: + azureDevOpsServiceConnection: '${{ parameters.azureDevOpsServiceConnection }}' + targetType: 'inline' + script: | + $token = Get-AzDoToken + + Write-Host "`nUse token with Azure DevOps REST API to list pools in the organization '$(System.CollectionUri)'..." + $apiVersion = "7.1-preview.1" + $apiUrl = "$(System.CollectionUri)_apis/distributedtask/pools?api-version=${apiVersion}" + Invoke-RestMethod -Uri $apiUrl ` + -Headers @{ + Accept = "application/json" + Authorization = "Bearer $token" + "Content-Type" = "application/json" + } ` + -Method Get ` + | Select-Object -ExpandProperty value ` + | Select-Object id, name \ No newline at end of file diff --git a/scripts/azure-devops b/scripts/azure-devops index 88259fa9..15c836a9 160000 --- a/scripts/azure-devops +++ b/scripts/azure-devops @@ -1 +1 @@ -Subproject commit 88259fa96296d41788cf35623d0e9916b5264b23 +Subproject commit 15c836a975013e63e28144c85e82fb84ea2c467f diff --git a/scripts/identity b/scripts/identity index ffcbd129..7fff30cd 160000 --- a/scripts/identity +++ b/scripts/identity @@ -1 +1 @@ -Subproject commit ffcbd129152037a7443f17a27962523561f5f5e3 +Subproject commit 7fff30cd994a7d7ce6edcd223acea53db4838c44 From cf15f816a69c1bffdcb5ff2b71e1eb2ceb31dd2e Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:55:59 +0100 Subject: [PATCH 6/7] Add parameter --- deployment/azure-service-connection-azdo-access.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/deployment/azure-service-connection-azdo-access.yml b/deployment/azure-service-connection-azdo-access.yml index 6166810e..34f4b8b3 100644 --- a/deployment/azure-service-connection-azdo-access.yml +++ b/deployment/azure-service-connection-azdo-access.yml @@ -1,4 +1,8 @@ parameters: +- name: azureDevOpsServiceConnection + displayName: Azure DevOps Service Connection + type: string + default: my-azdo-connection - name: serviceConnection displayName: Azure Service Connection Name type: string From 7822bb02c8532e02ae3b473db7a5546a95adfc68 Mon Sep 17 00:00:00 2001 From: Eric van Wijk Date: Tue, 26 Nov 2024 10:56:49 +0100 Subject: [PATCH 7/7] indent --- .../azure-service-connection-azdo-access.yml | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/deployment/azure-service-connection-azdo-access.yml b/deployment/azure-service-connection-azdo-access.yml index 34f4b8b3..ade232d4 100644 --- a/deployment/azure-service-connection-azdo-access.yml +++ b/deployment/azure-service-connection-azdo-access.yml @@ -91,23 +91,23 @@ jobs: | Select-Object id, name failOnStandardError: true -- task: PowerShell@2 - displayName: 'Get-AzDoToken' - inputs: - azureDevOpsServiceConnection: '${{ parameters.azureDevOpsServiceConnection }}' - targetType: 'inline' - script: | - $token = Get-AzDoToken + - task: PowerShell@2 + displayName: 'Get-AzDoToken' + inputs: + azureDevOpsServiceConnection: '${{ parameters.azureDevOpsServiceConnection }}' + targetType: 'inline' + script: | + $token = Get-AzDoToken - Write-Host "`nUse token with Azure DevOps REST API to list pools in the organization '$(System.CollectionUri)'..." - $apiVersion = "7.1-preview.1" - $apiUrl = "$(System.CollectionUri)_apis/distributedtask/pools?api-version=${apiVersion}" - Invoke-RestMethod -Uri $apiUrl ` - -Headers @{ - Accept = "application/json" - Authorization = "Bearer $token" - "Content-Type" = "application/json" - } ` - -Method Get ` - | Select-Object -ExpandProperty value ` - | Select-Object id, name \ No newline at end of file + Write-Host "`nUse token with Azure DevOps REST API to list pools in the organization '$(System.CollectionUri)'..." + $apiVersion = "7.1-preview.1" + $apiUrl = "$(System.CollectionUri)_apis/distributedtask/pools?api-version=${apiVersion}" + Invoke-RestMethod -Uri $apiUrl ` + -Headers @{ + Accept = "application/json" + Authorization = "Bearer $token" + "Content-Type" = "application/json" + } ` + -Method Get ` + | Select-Object -ExpandProperty value ` + | Select-Object id, name \ No newline at end of file