如何在Azure DevOps中的YAML阶段之间共享文件

问题描述 投票:1回答:1

我正在尝试使用Azure DevOps将我的node.js代码部署到Azure功能应用程序。我使用YAML创建了以下Azure DevOps管道。

我面临的问题是,在部署步骤中,我的管道失败,因为它无法找到package。当我查看日志时,我相信在作业/阶段之间的清理活动期间,文件夹会被清理。我已经尝试使用其他预定义变量,如Build.ArtifactStagingDirectory但没有效果。

trigger:
  - master

variables:
  azureServiceConnection: 'mySvcCon'
  azureFuncApp: myFApp

stages:
  - stage: Build_1
    displayName: 'Build Stage'
    jobs:
      - job: build
        displayName: 'Build Node.js app'
        pool:
          vmImage: 'Ubuntu-16.04'

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

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

          - task: CopyFiles@2
            displayName: 'Copy necessary files'
            inputs:
              SourceFolder: '$(System.DefaultWorkingDirectory)'
              Contents: |
                **/*
                !.vscode/**/*
              TargetFolder: '$(System.DefaultWorkingDirectory)/copied'

          - task: PublishBuildArtifacts@1
            displayName: 'Publish artifact'
            enabled: true
            inputs:
              PathtoPublish: '$(Build.ArtifactStagingDirectory)/copied'
              publishLocation: filePath
              targetPath: '$(System.DefaultWorkingDirectory)/publish'

  - stage: Deploy_2
    displayName: 'Deploy Stage'
    jobs:
      - job: Deploy
        displayName: 'Deploy to Function App'
        pool:
          vmImage: 'Ubuntu-16.04'

        steps:
          - task: AzureRMWebAppDeployment@4
            displayName: 'AzureRM Function App deploy'
            inputs:
              ConnectionType: 'AzureRM'
              ConnectedServiceName: $(azureServiceConnection)
              WebAppKind: 'Function App'
              WebAppName: $(azureFuncApp)
              Package: '$(System.DefaultWorkingDirectory)/publish'

如何在各个阶段之间共享我的工件?如果我将所有步骤放在同一个工作中,那么相同的管道就可以工但我想将它们分开。

azure-devops azure-pipelines azure-pipelines-build-task
1个回答
2
投票

通常 - 创建工件通常由Build Pipeline完成,而部署工件则在Release Pipeline中完成。绝对有机会根据您的使用情况在单个构建管道中执行这两个操作。当您刚刚开始使用Azure管道时,组合特别有意义,因为生态系统可能会有大量可用功能。有publicized work on merging the release capabilities into the build capabilities to simplify onboarding

如果第一次部署失败,分离管道确实可以为您提供重试部署的好处 - 这实际上取决于您的构建时间有多快。如果要手动触发环境或环状发布传播,还可以更轻松地支持跨环境部署相同位。用于分隔构建/部署grows exponentially once you dig into some of the power-user features of release stages的列表。

对于你的工作方式 - 你可以leverage the dependsOn YAML element to link the subsequent jobs to have an output dependency

Build Pipeline - Dependency Chaining

jobs:
- job: InitialA
  steps:
  - script: echo hello from initial A
- job: InitialB
  steps:
  - script: echo hello from initial B
- job: Subsequent
  dependsOn:
  - InitialA
  - InitialB
  steps:
  - script: echo hello from subsequent
© www.soinside.com 2019 - 2024. All rights reserved.