Search code examples
azureazure-devopsazure-devops-self-hosted-agent

In an Azure DevOps release pipeline how do you deploy to multiple VMs a deployment group with different target folders


I started out with a release pipeline setup in azure DevOps to deploy a windows service to a deployment group which had only a single VM with an agent set up. I have a variable set in the pipeline for the deployment folder.

I'm now trying to expand this to deploy to 2 servers. I've added the second server into the deployment group and the registration has worked. On this server, the deployment needs to go to a different drive.

There doesn't seem to be a way to specify a different value for the variable by an agent.

I've tried googling and trawling around in the ui and so far I've found nothing. I'm wondering if variables are even the right thing?


Solution

  • Im going to answer my own question as the solution is actually a combination of the answers kindly provided by @Martin A @Tomasz Kaniewski and @Vito Liu-MSFT with a fair amount trial and error. I hope this will help others.

    Environment Variables are the key to identifying the deployment folder so I set up a system environment variable called AutomationDeploymentRoot on each of my VM's

    You must restart the Azure Pipelines Agent windows service on each VM before changes to environment variables are picked up!!

    I found that the support for environment variables to be quite inconsistent between the different tasks - they seem to work well in script tasks but not so well in others such as CopyFiles.

    The most reliable approach was to copy the environment variable into a pipeline variable (deployment.root) which I set up on the variable tab like so

    Screen Shot of variables

    And then set the variable from script as suggested by Thomasz and Vito

    steps:
    - script: |
       @echo ##vso[task.setvariable variable=deployment.root]%AutomationDeploymentRoot%
       
      displayName: 'Set Deployment Folder'

    when this runs the c:\temp\deploy is replaced by the correct folder for the target machine and everything goes green!