SOLVED

Create deployment group using Azure CLI/powershell and assign a VM in release pipeline

%3CLINGO-SUB%20id%3D%22lingo-sub-1395498%22%20slang%3D%22en-US%22%3ECreate%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1395498%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Team%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20requirement%20to%20create%20a%20release%20pipeline%20as%20below%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20linux%20VM%20and%20I%20would%20like%20to%20automatically%20create%20a%20deployment%20group%20using%20azure%20cli%2Fpowershell%20and%20assign%20existing%20linux%20vm%20to%20be%20a%20part%20of%20deployment%20group.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20reply%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1395498%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDevOps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1395769%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1395769%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F668973%22%20target%3D%22_blank%22%3E%40Sagar_Lad%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23create%20VM%0A%23First-Level%0ANew-AzResourceGroup%20-Name%20PSAzureBootCampRG%20-Location%20westus%0A%20%20%20%20%24gatewaysubnet%20%3D%20New-AzVirtualNetworkSubnetConfig%20-Name%20PSGatewaySubnet%20-AddressPrefix%20%2210.172.100.0%2F27%22%0A%20%20%20%20%24virtualNetwork%20%3D%20New-AzVirtualNetwork%20-Name%20PSAzureBCVnet%20-ResourceGroupName%20PSAzureBootCampRG%20-Location%20westus%20-AddressPrefix%20%2210.172.100.0%2F24%22%20-Subnet%20%24gatewaysubnet%0A%20%20%20%20Add-AzVirtualNetworkSubnetConfig%20-Name%20AzureFirewallSubnet%20-VirtualNetwork%20%24virtualNetwork%20-AddressPrefix%20%2210.172.100.32%2F27%22%0A%20%20%20%20Add-AzVirtualNetworkSubnetConfig%20-Name%20PSDMZSubnet%20-VirtualNetwork%20%24virtualNetwork%20-AddressPrefix%20%2210.172.100.96%2F27%22%0A%20%20%20%20%24virtualNetwork%20%7C%20Set-AzVirtualNetwork%0A%0A%23Second-Level%20%0A%24publicipvm%20%3D%20New-AzPublicIpAddress%20-ResourceGroupName%20%22PSAzureBootCampRG%22%20-name%20%22VMIP%22%20-location%20%22westus%22%20-AllocationMethod%20Static%20-Sku%20Standard%0A%24resourceGroup%20%3D%20%22PSAzureBootCampRG%22%20%0A%24location%20%3D%20%22westus%22%20%0A%24vmName%20%3D%20%22VMName%22%20%0A%24cred%20%3D%20Get-Credential%20-Message%20%22Enter%20a%20username%20and%20password%20for%20the%20virtual%20machine.%22%20%0ANew-AzResourceGroup%20-Name%20%24resourceGroup%20-Location%20%24location%0ANew-AzVM%20-ResourceGroupName%20%24resourceGroup%20-Name%20%24vmName%20-Location%20%24location%20-ImageName%20%22RHEL%22%20-Size%20%22Standard_D2_v3%22%20-VirtualNetworkName%20%22PSAzureBCVnet%22%20-SubnetName%20%22PSDMZSubnet%22%20-PublicIpAddressName%20%24publicipvm%20-Credential%20%24cred%20-OpenPorts%2022%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1397181%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1397181%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F391034%22%20target%3D%22_blank%22%3E%40emreozanmemis%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20reply.%3C%2FP%3E%3CP%3EIt%20seems%20my%20requirement%20is%20bit%20different.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20I%20already%20have%20one%20resource%20group%2CLinux%20VM%20created.%3C%2FP%3E%3CP%3E2)%20I%20would%20like%20to%20create%20deployment%20group%20assigned%20to%20existing%20Linux%20VM%20using%20Powershell%2FCLI%20etc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20guide%20me%20on%20how%20to%20achieve%20the%20same%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1397498%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1397498%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F668973%22%20target%3D%22_blank%22%3E%40Sagar_Lad%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3ECan%20you%20check%20the%20links%20below%3F%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CA%20href%3D%22https%3A%2F%2Fwww.red-gate.com%2Fsimple-talk%2Fsysadmin%2Fpowershell%2Fazure-and-windows-powershell-using-vm-extensions%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fwww.red-gate.com%2Fsimple-talk%2Fsysadmin%2Fpowershell%2Fazure-and-windows-powershell-using-vm-extensions%2F%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdevops%2Fpipelines%2Frelease%2Fdeployment-groups%2Fhowto-provision-deployment-group-agents%3Fview%3Dazure-devops%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdevops%2Fpipelines%2Frelease%2Fdeployment-groups%2Fhowto-provision-deployment-group-agents%3Fview%3Dazure-devops%3C%2FA%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1400040%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1400040%22%20slang%3D%22en-US%22%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F391034%22%20target%3D%22_blank%22%3E%40emreozanmemis%3C%2FA%3E%2C%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20a%20lot%20for%20the%20update.%3CBR%20%2F%3EI%20will%20implement%20the%20solution%20and%20let%20you%20know%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1407721%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1407721%22%20slang%3D%22en-US%22%3Eit%20looks%20like%20you%20want%20to%20create%20a%20deployment%20group%20using%20PowerShell%3CBR%20%2F%3E%3CBR%20%2F%3E%24baseUri%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fdev.azure.com%2F%7Borganisation%7D%2F%7Bprojectname%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdev.azure.com%2F%7Borganisation%7D%2F%7Bprojectname%3C%2FA%3E%7D%22%3CBR%20%2F%3E%24accessToken%20%3D%20%5BSystem.Convert%5D%3A%3AToBase64String(%5BText.Encoding%5D%3A%3AUTF8.GetBytes(%22%3A%24(%24PersonalAccessToken)%22))%3CBR%20%2F%3E%24headers%20%3D%20%40%7B%3CBR%20%2F%3E%22Authorization%22%20%3D%20%22Basic%20%24(%24accessToken)%22%3CBR%20%2F%3E%22Content-Type%22%20%3D%20%22application%2Fjson%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%24uri%20%3D%20%22%24(%24baseUri)%2F_apis%2Fdistributedtask%2Fdeploymentgroups%3Fapi-version%3D5.1-preview.1%22%3CBR%20%2F%3E%24webResult%20%3D%20Invoke-WebRequest%20-Uri%20%24uri%20-Method%20Get%20-Headers%20%24headers%20-UseBasicParsing%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1405939%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1405939%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F391034%22%20target%3D%22_blank%22%3E%40emreozanmemis%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20sharing%20the%20link.%3C%2FP%3E%3CP%3EI%20have%20gone%20through%20the%20Microsoft%20link%20but%20it%20seems%20that%20links%20is%20more%20about%20how%20to%20install%20devops%20agent.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20looking%20for%20an%20option%20create%20deployment%20group%20using%20powershell%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1408949%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20deployment%20group%20using%20Azure%20CLI%2Fpowershell%20and%20assign%20a%20VM%20in%20release%20pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1408949%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F504311%22%20target%3D%22_blank%22%3E%40atulram%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20update%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hi Team,

 

I have a requirement to create a release pipeline as below :

 

I have a linux VM and I would like to automatically create a deployment group using azure cli/powershell and assign existing linux vm to be a part of deployment group.

 

Thanks for the reply

7 Replies

@Sagar_Lad 

 

 

#create VM
#First-Level
New-AzResourceGroup -Name PSAzureBootCampRG -Location westus
    $gatewaysubnet = New-AzVirtualNetworkSubnetConfig -Name PSGatewaySubnet -AddressPrefix "10.172.100.0/27"
    $virtualNetwork = New-AzVirtualNetwork -Name PSAzureBCVnet -ResourceGroupName PSAzureBootCampRG -Location westus -AddressPrefix "10.172.100.0/24" -Subnet $gatewaysubnet
    Add-AzVirtualNetworkSubnetConfig -Name AzureFirewallSubnet -VirtualNetwork $virtualNetwork -AddressPrefix "10.172.100.32/27"
    Add-AzVirtualNetworkSubnetConfig -Name PSDMZSubnet -VirtualNetwork $virtualNetwork -AddressPrefix "10.172.100.96/27"
    $virtualNetwork | Set-AzVirtualNetwork

#Second-Level 
$publicipvm = New-AzPublicIpAddress -ResourceGroupName "PSAzureBootCampRG" -name "VMIP" -location "westus" -AllocationMethod Static -Sku Standard
$resourceGroup = "PSAzureBootCampRG" 
$location = "westus" 
$vmName = "VMName" 
$cred = Get-Credential -Message "Enter a username and password for the virtual machine." 
New-AzResourceGroup -Name $resourceGroup -Location $location
New-AzVM -ResourceGroupName $resourceGroup -Name $vmName -Location $location -ImageName "RHEL" -Size "Standard_D2_v3" -VirtualNetworkName "PSAzureBCVnet" -SubnetName "PSDMZSubnet" -PublicIpAddressName $publicipvm -Credential $cred -OpenPorts 22

Hi @emreozanmemis ,

 

Thanks for the reply.

It seems my requirement is bit different.

 

1) I already have one resource group,Linux VM created.

2) I would like to create deployment group assigned to existing Linux VM using Powershell/CLI etc.

 

Could you guide me on how to achieve the same?

Hi @emreozanmemis,

Thanks a lot for the update.
I will implement the solution and let you know

Hi @emreozanmemis ,

 

Thanks for sharing the link.

I have gone through the Microsoft link but it seems that links is more about how to install devops agent.

 

I am looking for an option create deployment group using powershell

best response confirmed by Sagar_Lad (Contributor)
Solution
it looks like you want to create a deployment group using PowerShell

$baseUri = "https://dev.azure.com/{organisation}/{projectname}"
$accessToken = [System.Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(":$($PersonalAccessToken)"))
$headers = @{
"Authorization" = "Basic $($accessToken)"
"Content-Type" = "application/json"
}

$uri = "$($baseUri)/_apis/distributedtask/deploymentgroups?api-version=5.1-preview.1"
$webResult = Invoke-WebRequest -Uri $uri -Method Get -Headers $headers -UseBasicParsing