Azure管道空对象

x33g5p2x  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(73)

我试图创建一个构建管道,然后部署在我的临时服务器和Live服务器上。

trigger:
- main

variables:
  uiSource: 'dashboard'

pool:
  vmImage: 'windows-2019'

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

- script: |
    pushd $(uiSource)
    npm install
    npm run build
    popd
  displayName: 'npm install and build'
    
- task: PublishPipelineArtifact@0
  displayName: 'Publish pipeline artifact'
  inputs:
    artifactName: 'myArtifact'
    targetPath: '$(Build.ArtifactStagingDirectory)'

我尝试添加,但这只是复制目录中的所有内容。我只对生成的构建感兴趣。

- task: CopyFiles@2
  displayName: Copy file into artifacts
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

我尝试在VS代码中运行npm build,它工作正常,并创建了一个构建文件夹。构建的结果是手动部署的,工作正常。我只是试图在这里复制相同的内容
我已经更新到下面,但它现在生成一个空的zip文件

trigger:
  batch: true
  branches:
    include:
      - main

  paths:
    include:
    - dashboard/*

pool:
  vmImage: 'windows-2019'

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

- script: |
    npm install
    npm run build
  displayName: 'npm install and build'
  workingDirectory: 'dashboard/'

- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/FrontEnd.zip'
    replaceExistingArchive: true
    
- task: PublishBuildArtifacts@1
  name: 'PublishArtifacts'
  displayName: 'Publish Artifacts'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'FrontEnd'
    publishLocation: 'Container'
lndjwyie

lndjwyie1#

'npm install and build'后,添加复制任务,并更改SourceFolder名称。如果在本地名为'build',则应为SourceFolder: 'build'

- task: CopyFiles@2
  displayName: 'Copy Files to Artifact Staging Directory'
  inputs:
    SourceFolder: 'public'
    Contents: '**'
    TargetFolder: '$(build.artifactstagingdirectory)'
    CleanTargetFolder: true
    OverWrite: true

我通常使用zip和PublishBuildArtifacts@1。

- task: ArchiveFiles@2
  displayName: 'Zip Artifact Staging Directory to yourproject.zip'
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/yourproject.zip'
    replaceExistingArchive: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Build Artifacts'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/yourproject.zip'
    ArtifactName: 'your-project'
    publishLocation: 'Container'

相关问题