Sole
Sole

Reputation: 3340

Azure DevOps - Drop folder empty in React build for Azure YAML pipeline

I am trying to implement the YAML pipeline into my project; however, the current code does not give not output into the drop folder. I don't have any subfolders. The project is at the root. Any ideas? I have seen somewhere that in the scripts part I need pushd to specify directory and popd at the end.

Project structure:

enter image description here

I have seen this tutorial: https://www.youtube.com/watch?v=QbmLxfRCt38&t=406s but how would I specify the root folder.

trigger:
- master

pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run build
  displayName: 'npm install and build'

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

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

Upvotes: 0

Views: 1361

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40583

You archive Build.BinariesDirectory which is:

The local path on the agent you can use as an output folder for compiled binaries.

By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab.

For example: c:\agent_work\1\b.

This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag.

And usually npm produces dist directory located nera to your code. So this is for sure wrong path to archive.

Your step should be rather

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

bit to be sure please add temporary step like

- bash: ls src

after 'npm install and build' step.

trigger:
- master

pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run build
  displayName: 'npm install and build'

- bash: ls src
  displayName: 'Check directories'

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


- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    ArtifactName: 'drop'

Upvotes: 2

Related Questions