Azure DevOps S3 React / MERN堆栈

发布时间:2020-07-07 05:17

有没有人有使用Azure DevOps使用其扩展程序将React build package部署到AWS的经验?

我只能上传npm build的构建包。

到目前为止,这是我的脚本:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

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

- script: |
    npm install
    npm test
    npm run build
    - task: S3Upload@1
      inputs:
        awsCredentials: 'AWS Deploy User'
        regionName: 'us-east-1'
        bucketName: 'test'
        globExpressions: '**'
        createBucket: true
  displayName: 'npm install and build'

在S3Upload任务中唯一突出的选项是sourceFolder。他们使用"$(Build.ArtifactStagingDirectory)"之类的东西,但是由于我之前从未使用过,所以对我来说没有多大意义。就像$(Build.ArtifactStagingDirectory)/build

这样简单吗

enter image description here

回答1

predefined variable $(Build.ArtifactStagingDirectory)映射到c:\agent_work\1\a,这是代理上任何工件被复制到目的地之前被复制到的本地路径。

在yaml管道中,源代码下载到文件夹$(Build.SourcesDirectory)(即c:\agent_work\1\s)中。脚本任务中的npm命令都在此文件夹中运行。因此,npm构建结果是此文件夹$(Build.SourcesDirectory)\build(即c:\ agent_work \ 1 \ s \ build)。

S3Upload任务将默认从$(Build.ArtifactStagingDirectory)上传文件。您可以将S3Upload任务的sourceFolder属性(默认为$(Build.ArtifactStagingDirectory))指向文件夹$(Build.SourcesDirectory)\build。见下文:

- task: S3Upload@1
      inputs:
        awsCredentials: 'AWS Deploy User'
        regionName: 'us-east-1'
        bucketName: 'test'
        globExpressions: '**'
        createBucket: true
        sourceFolder: '$(Build.SourcesDirectory)/build'

另一个解决方法是使用复制文件任务将构建结果从$(Build.SourcesDirectory)\build复制到文件夹$(Build.ArtifactStagingDirectory)。参见示例here

- task: CopyFiles@2
  inputs:
    Contents: 'build/**' # Pull the build directory (React)
    TargetFolder: '$(Build.ArtifactStagingDirectory)'