Azure DevOps - 在 Azure YAML 管道的 React 构建中删除空文件夹

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

我正在尝试将 YAML 管道实施到我的项目中;但是,当前代码不会输出到放置文件夹中。我没有任何子文件夹。该项目位于根部。有任何想法吗?我在某个地方看到,在脚本部分我需要 pushd 来指定目录并在最后弹出。

项目结构:

我看过这个教程:https://www.youtube.com/watch?v=QbmLxfRCt38&t=406s但是我该如何指定根文件夹。

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'

您存档 Build.BinariesDirectory 即:

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\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.

通常 npm 会为您的代码生成 dist 位于 nera 的目录。所以这肯定是错误的归档路径。

你的脚步应该比较

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

有点确定请添加临时步骤

- bash: ls src

'npm install and build' 步骤之后。

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'