使用 Azure DevOps 进行增量部署

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

我的项目中有多个解决方案。我只需要部署开发团队已进行更改的解决方案。

首先这可能吗?如果是的话我们如何才能实现它。

我们创建了一个构建管道和一个发布管道,并认为它只会复制更新的文件,但它正在复制所有工件。

我们期望它应该只复制更新的 dll。

azure-devops continuous-integration azure-pipelines continuous-deployment
1个回答
0
投票

假设您有一个存储库,其中包含不同路径中的多个解决方案,如下图所示;

Image

根据您的需求,您可以运行

git diff
命令来了解更改提交被推送到哪个路径,从而确定是否构建这些解决方案

这里有一个示例 YAML 管道供您参考。

parameters:
- name: SLNs
  type: object
  default:
  - Solution1
  - Solution2

stages:
- stage: CI
  jobs:
  - job: Build
    steps:
    - checkout: self
      fetchDepth: 0 # Set fetchDepth as 0 to disable default shallowfetch and make sure git diff command works

    - ${{ each SLN in parameters.SLNs }}:
      - powershell: |
          Write-Host "Build.SourceVersion is $(Build.SourceVersion)"

          # Check if there are changes in ${{SLN}}
          if (git diff --name-only $(Build.SourceVersion)^ $(Build.SourceVersion) -- ${{SLN}}) {
              Write-Host "Changes detected in ${{SLN}}"
              Write-Host "##vso[task.setvariable variable=build${{SLN}}]True"
          }
          else {
            Write-Host "No changes detected in ${{SLN}}"
          }
        displayName: 'Determine to Build ${{SLN}}'
      - task: DotNetCoreCLI@2
        inputs:
          command: 'build'
          projects: '${{SLN}}/*.sln'
          arguments: '-o:$(Build.BinariesDirectory)'
        displayName: 'Build ${{SLN}}'
        condition: eq(variables['build${{SLN}}'], 'True')
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Build.BinariesDirectory)'
        Contents: '*.dll'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
      displayName: Copy .dll files 
    - publish: $(Build.ArtifactStagingDirectory)
      artifact: drop

- stage: CD
  jobs:
  - deployment: Deploy
    environment: E-Test
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              tree $(Pipeline.Workspace) /F /A
            displayName: Check artifacts

Image

但是,如果一次推送中不同路径下有多个提交,则它可能可靠。因此,仍然建议创建单独的管道以由特定的路径过滤器触发,并继续在该路径中构建和发布解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.