How to change Azure DevOps environment agent folder structure

1k Views Asked by At

To achieve continuous deployment, we used a (classic) release pipeline on Azure DevOps to deploy a webservice to a VM in our intranet. To benefit of a yaml deployment pipeline, I replaced our former deployment pool agent on that VM with an environment agent.

For the actual deployment, we use the IIS Web App Deploy task. The source directory for this tasks defaults to $(System.DefaultWorkingDirectory)\**\*.zip. The $(System.DefaultWorkingDirectory) translates to the a subdirectory of the concrete release.

Unfortunately for me, the environment agent downloads the artifact next to the a-folder instead of into it like the environment pool agent. Thus the default settings of the deploy task cannot find it. I am aware that I can easily work around this issue by using $(System.DefaultWorkingDirectory)\..\**\*.zip. I was just wondering why Microsoft introduced such a development speed bump into the environment agents.

Is there any way I can make the environment agent download the artifact into $(System.DefaultWorkingDirectory) aka. a instead of next to it?

3

There are 3 best solutions below

0
On BEST ANSWER

If you are using deployment job in yaml pipeline. The artifacts will be automatically downloaded to $(Pipeline.Workspace)/(folder next to $(System.DefaultWorkingDirectory)) in deployment jobs. See below extract from here:

  • Artifacts from the current pipeline are downloaded to $(Pipeline.Workspace)/.

  • Artifacts from the associated pipeline resource are downloaded to $(Pipeline.Workspace)/{pipeline resource identifier}/.

  • All available artifacts from the current pipeline and from the associated pipeline resources are automatically downloaded in deployment jobs and made available for your deployment. To prevent downloads, specify download: none.

To make the environment agent download the artifact into $(System.DefaultWorkingDirectory).

You can specify download: none. And use Download Pipeline Artifacts task and specify the path parameter to download your artifacts to $(System.DefaultWorkingDirectory). See below:

 - deployment: 
   environment: Dev
   strategy:
     runOnce:    
       deploy:
         steps:
         - download: none #prevent automatically download

         - task: DownloadPipelineArtifact@2
           inputs:
             buildType: 'current'
             targetPath: '$(System.DefaultWorkingDirectory)'  # download to default folder.

Anther workaround is to change the source directory for IIS Web App Deploy task defaults to $(Pipeline.Workspace)\**\*.zip

0
On

When changing from Classic to YAML pipelines for deployments, you will probably need to change $(System.DefaultWorkingDirectory) to $(Pipeline.Workspace). You can verify this with the steps:

- pwsh: Get-ChildItem $(System.DefaultWorkingDirectory) -Recurse
  displayName: Check System.DefaultWorkingDirectory
- pwsh: Get-ChildItem $(Pipeline.Workspace) -Recurse
  displayName: Check Pipeline.Workspace

(Yes, this is an awfully verbose way of doing it. It will, though, give you more complete insight into the file structure supporting your job.)

0
On

If you are tying to configure the azure env. then cd the drive and change the script "SystemDrive" with your drive name.

cd $env:SystemDrive\'azagent'