Forum Discussion

Sagar_Lad's avatar
Sagar_Lad
Brass Contributor
May 16, 2020

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

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

  • atulram's avatar
    atulram
    May 21, 2020
    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
  • emreozanmemis's avatar
    emreozanmemis
    Steel Contributor

    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

Resources