2

I need to move files from ADO to a VM. This VM is set up using "Environments" and tagged appropriately. I would like to copy those files to that VM using its environment name and tag. So far I've only found "Windows machine file copy" which requires storing a admin login. Is there a way to use the Environments instead of hardcoding a login?

3
  • What does your YAML look like? If you're running your deployment on an environment, you don't need to copy build artifacts, because the agent on each machine can download them. Commented Jun 30, 2021 at 19:07
  • well right now i don't have the yaml written because i'm not sure what to use. Could you send me a link to something that would help? It's literally just a file copy. Commented Jun 30, 2021 at 19:17
  • @c0d3w1thW1NG5 Common way to store passwords is Variable Group, in that way it will be secure and reusable in multiple places learn.microsoft.com/en-us/azure/devops/pipelines/library/… Commented Jul 1, 2021 at 3:31

2 Answers 2

3

You can set up the YAML pipeline like as below:

  1. If you want to copy the build artifact files to the VM, reference below sample.
    • In the Build stage set up the jobs to build the source code, and publish the artifact files for use.

    • In the Deploy stage, when setting the deployment job with an environment on an VM, all steps in this job will be run on this VM. In the deployment job, at the very first step, it will automatically download the artifact files to the working directory on the VM.

    • Then you can use the CopyFiles task to the copy the artifact files to any accessible directory on the VM.

stages:
- stage: Build
  displayName: 'Build'
  . . .

- stage: Deploy
  displayName: 'Deploy'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deployment
    displayName: 'Deployment'
    environment: '{EnvironmentName.ResourceName}'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: CopyFiles@2
            displayName: 'Copy Files to: {Destination Directory}'
            inputs:
              SourceFolder: '$(Pipeline.Workspace)/drop'
              Contents: '**'
              TargetFolder: '{Destination Directory}'
              CleanTargetFolder: true
  1. If the files you want to copy the VM are the source files in the repository, reference below sample.
stages:
- stage: Deploy
  displayName: 'Deploy'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deployment
    displayName: 'Deployment'
    environment: '{EnvironmentName.ResourceName}'
    strategy:
      runOnce:
        deploy:
          steps:
          - checkout: self

          - task: CopyFiles@2
            displayName: 'Copy Files to: {Destination Directory}'
            inputs:
              SourceFolder: '$(Pipeline.Workspace)'
              Contents: '**'
              TargetFolder: '{Destination Directory}'
              CleanTargetFolder: true

For more details, you can see: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/environments-kubernetes?view=azure-devops

Sign up to request clarification or add additional context in comments.

Comments

1

I have been struggling for a while with setting up an Azure Pipeline to deploy .Net Core service to VM. I had the following requirements:

  1. to use YAML files instead of classic UI
  2. to deploy as a windows service not to IIS
  3. to use stages in pipeline
  4. I was using monorepo with the service residing in MyService folder
  5. In addition I had an external NuGet feed
  6. My solution consisted of several projects and I was building only one of them
  7. appsettings.release.json was being replaced with the one persisted on the server to preserve settings

I was inspired by Bright Ran-MSFT answer and suggest my complete azure-pipelines.yml file

trigger:
  branches:
    include:
      - staging
  paths:
    include:
      - MyService

pool:
  vmImage: "windows-latest"

variables:
  solution: "MyService/MyService.sln"
  buildPlatform: "Any CPU"
  buildConfiguration: "Release"

stages:
  - stage: Build
    jobs:
      - job: BuildJob
        steps:
          - task: NuGetCommand@2
            inputs:
              restoreSolution: "$(solution)"
              feedsToUse: "config"
              nugetConfigPath: "MyService/NuGet.Config"
          - task: VSBuild@1
            inputs:
              solution: "$(solution)"
              msbuildArgs: '/t:MyService:Rebuild /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:OutDir="$(build.artifactStagingDirectory)\service_package"'
              platform: "$(buildPlatform)"
              configuration: "$(buildConfiguration)"
          - task: VSTest@2
            inputs:
              platform: "$(buildPlatform)"
              configuration: "$(buildConfiguration)"
          - task: PublishPipelineArtifact@1
            inputs:
              targetPath: '$(build.artifactStagingDirectory)\service_package'
              artifactName: "service_package"
  - stage: Deploy
    displayName: 'Deploy'
    dependsOn: Build
    condition: succeeded()
    jobs:
      - deployment: Deployment
        displayName: 'Deployment'
        environment: 'MainDeployEnv.MY_VM_SERVER'
        strategy:
          runOnce:
            deploy:
              steps:
                - task: CopyFiles@2
                  displayName: 'Copy Package to: C:\azservices\MyService\service'
                  inputs:
                    SourceFolder: '$(Pipeline.Workspace)/service_package'
                    Contents: '**'
                    TargetFolder: 'C:\azservices\MyService\service\'
                    CleanTargetFolder: true
                - task: CopyFiles@2
                  displayName: 'Replace appsettings.release.json'
                  inputs:
                    SourceFolder: 'C:\azservices\MyService\settings'
                    Contents: 'appsettings.release.json'
                    TargetFolder: 'C:\azservices\MyService\service\'
                    OverWrite: true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.