映射 yarn 构建输出以暂存工件

Map yarn build output to stage an artifact

我正在尝试使用 Azure DevOps yarn YAML 任务来构建我的网站。该步骤完成。但是构建的代码去了哪里?

##[section]Starting: Yarn   
    Task         : Yarn task
Description  : Executes Yarn
Version      : 2.8.1001
Author       : Geek Learning
Help         : [More Information](https://github.com/geeklearningio/gl-vsts-tasks-yarn/wiki/Yarn) (Version 2.8.1001).

Dear Angular and Ember CLI users, please check our [known issues](https://github.com/geeklearningio/gl-vsts-tasks-yarn/wiki/Known-Issues)
==============================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
    [command]C:\windows\system32\cmd.exe /D /S /C "C:\npm\prefix\yarn.cmd --production build"
yarn install v1.15.2
    [1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.4: The platform "win32" is incompatible with this module.
    info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
    info fsevents@1.2.7: The platform "win32" is incompatible with this module.
    info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
    [3/4] Linking dependencies...
warning " > bootstrap@4.3.1" has unmet peer dependency "jquery@1.9.1 - 3".
    warning " > bootstrap@4.3.1" has unmet peer dependency "popper.js@^1.14.7".
    [4/4] Building fresh packages...
Done in 119.26s.
##[section]Finishing: Yarn



##[section]Starting: Stage Files
    ==============================================================================
    Task         : Copy Files
Description  : Copy files from source folder to target folder using match patterns (The match patterns will only match file paths, not folder paths)
Version      : 2.117.2
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=708389)

##[error]Unhandled: Not found SourceFolder: D:\a\a\s\build\
##[section]Finishing: Stage Files

这是我的 YAML

task: Yarn@2
inputs:
    ProjectDirectory: './'
Arguments: 'build'
ProductionMode: true

    - task: CopyFiles@2
displayName: 'Stage Files'
inputs:
    SourceFolder: 'D:\_work\s\build'
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)/dist'
CleanTargetFolder: true
OverWrite: true      

我一直在玩 SourceFolder,但运气不好。

添加 "dir" 命令似乎表明我在项目的根文件夹中,但我没有看到构建文件夹

我认为问题是 "yarn build" 似乎在工作,但它只是在安装 yarn。

我在 "yarn --production" 之后向 "yarn build" 添加了第二个命令。

- task: Yarn@2
inputs:
    ProjectDirectory: './'
ProductionMode: true

    - task: Yarn@2
inputs:
    ProjectDirectory: './'
Arguments: 'build'

    - script: "dir .."
displayName: 'Run dir'

    - task: CopyFiles@2
displayName: 'Stage Files'
inputs:
    SourceFolder: './build'
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)/dist'
CleanTargetFolder: true
OverWrite: true      
##[error]Unhandled: Not found SourceFolder: D:\a\a\s\build\

根据这个消息,我认为错误是由于 source folder 的路径没有被正确指定造成的。

正如我在评论中提到的,此值与您的代理本地路径相关。反正不管agent是什么,都可以用一个相同的变量来获取:Build.SourcesDirectory

它是一个predefined variable,它可以获取您的源代码文件下载到的代理上的本地路径。

因此,我的建议是:将您的 SourceFolder 值修改为

inputs:
SourceFolder: '$(Build.SourcesDirectory)'

获取正确的构建路径。