Gus Mueller
Gus Mueller

Reputation: 126

How to specify a destination path on a virtual machine resource in a Azure DevOps deployment using multi-stage YAML

I'm new to Azure DevOps so I'm trying to understand how to specify things in YAML. I understand that Deployment Groups are not currently reachable directly with a multi-stage YAML pipeline, though I am able to automate deployment to a virtual machine in a Deployment Group using separate build and release pipelines (the second being created graphically in a GUI in a manner that doesn't permit me to see or modify the source, which makes me nervous for several reasons).

What I want to do instead is have a multi-stage YAML pipeline that deploys to that same virtual machine inside an "environment," which I understand IS possible with multi-stage YAML pipelines. What I've never yet seen documented is how to specify where on the virtual machine the deployment ends up. If I want, for example, to deploy to C:\spaghetti\meatball on my virtual machine, how would I specify that in the deploy stage of a YAML pipeline?

UPDATE: This YAML seems to work (work secrets have been obscured, of course):

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'



stages: 
- stage: build
  displayName: Build
  jobs:
  - job: Build

    steps:
    - checkout: self
    #without this first one, bad things happen!!
    - task: NuGetCommand@2
      inputs:
        command: 'restore'
        restoreSolution: '**/*.sln'
        feedsToUse: 'config'
        nugetConfigPath: 'NuGet.config'
        
    - task: NuGetToolInstaller@1


    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'


- stage: Release
  displayName: Release
  condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
  jobs:

  - deployment:
    displayName: Release
    environment: 
        name: QA
        resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - task: CopyFiles@2
            inputs:  
              #ONLY COPIES AN UGLY .ZIP, BUT GOOD ENOUGH FOR HELLO WORLD
              SourceFolder: '$(Agent.WorkFolder)\1\drop'
              Contents: '**\*.zip'
              OverWrite: true
              #ACTUAL TARGET ON THE SERVER
              TargetFolder: 'C:\QA\XXXXX\YYYYY'

Upvotes: 1

Views: 847

Answers (1)

Daniel Mann
Daniel Mann

Reputation: 59045

Deployment groups and YAML deployment jobs targeting machines within an environment function roughly equivalently -- the artifacts are downloaded to a working location on the machine that is running the agent. Then you can copy them to the desired destination. This would just be a step within your pipeline.

Upvotes: 0

Related Questions