James Monger
James Monger

Reputation: 10675

Publish build artifact from folder without including root folder

On Azure DevOps, I have some files I want to publish:

I want to publish them into an artifact app.zip which contains, at the root level: - index.html - bundle.js

However when I use the "Publish Build Artifacts" tasks with the path set to $(Build.ArtifactStagingDirectory)/dist/app, I get the following contents in app.zip:

I tried setting the publish path to:

but all of these fail the build with the error Not found PathtoPublish

Upvotes: 2

Views: 1738

Answers (2)

sparkfly
sparkfly

Reputation: 11

I am currently at the same crossroad as OP. The above answer does not work. What worked for me:

  • Create a task to archive the files you want with the input includeRootFolder set to false
  • At the publish task, as input PathtoPublish, use the same input given at the archive task

Example:

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)\dist\app'
    includeRootFolder: false 
    archiveType: 'zip' 
    archiveFile: '$(Build.ArtifactStagingDirectory)\app.zip'

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

Note: This example will mean that the published artifact with the name 'drop' will be available. If you download that, you will get a drop.zip file as the downloaded file. Instead of that, you should open the folder and download the zip folder already set in the drop folder.

Cheers.

Upvotes: 1

Ajay Panigrahi
Ajay Panigrahi

Reputation: 1

if I understand your question , you trying to publish 2 files as your atficats. as you are already ready with app.zip may be first retry copying it to another staging folder and then try to copy it from there. or see the below pattern to traverse through the directories. then you need - task: PublishBuildArtifacts inputs:

 pathtoPublish: $(Build.ArtifactStagingDirectory)/**/*
artifactName: MyBuildOutputs

Cheers. AJ

Upvotes: -1

Related Questions