David Pepper
David Pepper

Reputation: 33

Using Azure Devops yaml pipelines to deploy to on-prem servers

When using Azure DevOps pipelines, is it possible to deploy to on-prem servers using a yaml pipeline?

I have deployed to on premise servers with a Release (classic) pipeline using deployment groups, and I have seen instructions on deploying to Azure infrastructure using yaml pipelines.

However I can't find any examples of how to deploy to on-prem servers using yaml pipelines - is this possible yet? If so are there any examples available of how to achieve this?

Upvotes: 3

Views: 4670

Answers (2)

Thomas
Thomas

Reputation: 29472

As already explained in the previous answers, you need to create a new environment and add VMs to the environment (see documentation).

Using a deployment job, you also need to specify the resourceType

- deployment: VMDeploy
  displayName: Deploy to VM
  environment:
    name: ContosoDeploy
    resourceType: VirtualMachine
...

If you have multiple VMs in this environment, the job steps will be executed on all the VMs.

To target specific VMs, you can add tags (see documentation).

jobs:
- deployment: VMDeploy
  displayName: Deploy to VM
  environment: 
    name: ContosoDeploy
    resourceType: VirtualMachine
    tags: windows,prod # only deploy to virtual machines with both windows and prod tags
...

Upvotes: 4

James Reed
James Reed

Reputation: 14052

Yes you can. In YAML pipelines you can use "Environments" as a replacement for deployment groups. They work in a similar way in that you install the agent on the target machine and then specify the environment in your Deployment Job

Create a new Environment with an appropriate name (e.g. Dev) then add a resource, you'll be able to add either a VM or a Kubernetes cluster. Assuming that you choose VM, then you will able to download a script which you can run an target machines to install the deployment agent. This script will install and register the agent in to the environment.

Once you have the Agent registered in to the environment add a deployment job to your YAML

- stage: DeployToDev
  displayName: Deploy to Dev
  jobs:
  - deployment: DeployWebSite
    displayName: Deploy web site to Dev
    environment: Dev
    strategy:
      runOnce:
        deploy:
          steps:
            - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Deploy my code"         

Upvotes: 3

Related Questions