CREATE DOCKER REGISTRY DEVOPS SERVICE CONNECTION WITH PAT AS USER INPUT (Create-Docker-Registry-DevOps-Service-Connection-Prompt-PAT.ps1):-
##############
# VARIABLES:-
##############
$devopsOrg = "https://dev.azure.com/arindammitra0251/"
$devopsPrj = "AMCLOUD"
$configJSON = "acr-srv-connection.json"
$dockersrvconn = "AM-ACR-Srv-Connection"
##############
# CORE SCRIPT:-
##############
# Perform DevOps Login. It will Prompt for PAT:-
az devops login
# Set Default DevOps Organisation and Project:-
az devops configure --defaults organization=$devopsOrg project=$devopsPrj
# Create DevOps Service Connection:-
az devops service-endpoint create --service-endpoint-configuration .\$configJSON
# Grant Access to all Pipelines to the Newly Created Docker Registry DevOps Service Connection:-
$srvEndpointID = az devops service-endpoint list --query "[?name=='$dockersrvconn'].id" -o tsv
az devops service-endpoint update --id $srvEndpointID --enable-for-all
USE CASE #2:-
CREATE DOCKER REGISTRY DEVOPS SERVICE CONNECTION WITH PAT AS ENVIRONMENT VARIABLE (Create-Docker-Registry-DevOps-Service-Connection-Without-Prompting-PAT.ps1):-
##############
# VARIABLES:-
##############
$pat = "<Provide your own PAT>"
$devopsOrg = "https://dev.azure.com/arindammitra0251/"
$devopsPrj = "AMCLOUD"
$configJSON = "acr-srv-connection.json"
$dockersrvconn = "AM-ACR-Srv-Connection"
##############
# CORE SCRIPT:-
##############
# Set environment variable for DevOps Login:-
$env:AZURE_DEVOPS_EXT_PAT = $pat
# Set Default DevOps Organisation and Project:-
az devops configure --defaults organization=$devopsOrg project=$devopsPrj
# Create DevOps Service Connection:-
az devops service-endpoint create --service-endpoint-configuration .\$configJSON
# Grant Access to all Pipelines to the Newly Created Docker Registry DevOps Service Connection:-
$srvEndpointID = az devops service-endpoint list --query "[?name=='$dockersrvconn'].id" -o tsv
az devops service-endpoint update --id $srvEndpointID --enable-for-all
1. Please change the values of the variables accordingly.
2. The entire script is build using Variables. No Values are Hardcoded. Changing the values of the variables should help you execute the script seamlessly.
3. In Use Case #1, PAT is User Input, and in Use Case #2, PAT is defined as Variable and then passed as Environmental Variable for DevOps Login.
4. The Value of the Variable "$configJSON" is the Custom Name of the JSON Format Configuration File.
5. The Value of the Variable "$dockersrvconn" is the Custom Name of Docker Registry DevOps Service Connection. Please Remember to keep the Custom Name of Docker Registry Service Connection Same in both files - 1) In JSON Format Configuration, and 2) In Powershell Script.
CORE SCRIPT:-
Perform DevOps Login. It will Prompt for PAT Token:-
az devops login
OR
Set PAT as an environment variable for DevOps Login:-
$env:AZURE_DEVOPS_EXT_PAT = $pat
Set Default DevOps Organisation and Project:-
az devops configure --defaults organization=$devopsOrg project=$devopsPrj
Create Docker Registry DevOps Service Connection using the JSON Format Configuration File:-
az devops service-endpoint create --service-endpoint-configuration .\$configJSON
Grant Access to all Pipelines to the Newly Created Docker Registry DevOps Service Connection:-
$srvEndpointID = az devops service-endpoint list --query "[?name=='$dockersrvconn'].id" -o tsv
az devops service-endpoint update --id $srvEndpointID --enable-for-all
NOW ITS TIME TO TEST:-
TEST CASES:-
1. Output of the script when executed successfully.
Output Continued...
2. Docker Registry DevOps Service Connection created successfully with access granted to all pipelines.
Output Continued...
Hope You Enjoyed the Session!!!
Stay Safe | Keep Learning | Spread Knowledge
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)