1

My Azure DevOps pipeline is successfully packing up my web service into a zip file with the following task:

- task: DotNetCoreCLI@2
  displayName: Pack Artifacts
  inputs:
    command: 'publish'
    publishWebProjects: false
    arguments: '"Web Service" --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'

This deposits the entire contents of the project in a zip file in 'drop\a.zip'. Now, I have a script (setup.ps1) that I want to run to open up the firewall and an SSL certificate that needs to be installed. I want to add them to the same zip file that was the target for the 'publish' operation. I tried this:

- task: CopyFiles@2
  inputs:
    SourceFolder: 'Additional Files'
    Contents: '*'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
    flattenFolders: true

But it just added the files in the 'Additional Files' directory to the "\drop" directory alongside the a.zip file:

drop
  a.zip
  setup.ps1
  www_mysite_com.pfx

How would I go about adding the additional files to the zip file that's created as part of the build and publish steps. This must be a common problem. What's the common solution?

Quark Soup
  • 4,272
  • 3
  • 42
  • 74
  • Not get your latest information. Just want to check whether below answers are helpful for you? If yes, you can accept one answer which can also benefit for others who has same puzzle with you and we could archive this thread. Also, feel free to leave comment below if still has any puzzle about it:-) – Hugh Lin Jan 22 '21 at 07:12

2 Answers2

0

You have three options:

  • unpack archive, copy file and pack again
  • add file to archive - like it is shown here
  • add your file to solution and make dotnet publish responsible for putting file in archive like it is shown here
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
0

Your artifacts directory should be

drop
  a.zip

And now, you want to add setup.ps1 and www_mysite_com.pfx to the folder a, right?

YAML sample:

- task: DotNetCoreCLI@2
  displayName: Pack Artifacts
  inputs:
    command: 'publish'
    publishWebProjects: false
    arguments: '"Web Service" --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'

#Extract a.zip file to $(Build.ArtifactStagingDirectory)/drop/a folder

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/drop/a.zip'
    destinationFolder: '$(Build.ArtifactStagingDirectory)/drop/a'
    cleanDestinationFolder: false
    overwriteExistingFiles: false

#Delete PrescQIPPWebApp.zip file
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Remove-Item ''$(Build.ArtifactStagingDirectory)/drop/a.zip'''

#copy these files to the folder a
- task: CopyFiles@2
  inputs:
    SourceFolder: 'Additional Files'
    Contents: |
      setup.ps1
      www_mysite_com.pfx
    TargetFolder: '$(Build.ArtifactStagingDirectory)/drop/a'
    OverWrite: true
    flattenFolders: true

#Archive folder a to a.zip

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/drop/a'
    includeRootFolder: true
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/drop/a.zip'
    replaceExistingArchive: true


#Delete a folder
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Remove-Item -path ''$(Build.ArtifactStagingDirectory)/drop/a'' -Recurse -Force -EA SilentlyContinue -Verbose'

#And now, we could the a.zip contain the file setup.ps1 and www_mysite_com.pfx.

We could also check this Thread Adding additional files to Azure Build Pipeline

Vito Liu
  • 7,525
  • 1
  • 8
  • 17