依赖管道无法继续部署

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

我有一个管道 (MainPipeline),它会触发另一个管道 (DependantPipeline)。

我想在主管道(构建和测试阶段)中完成一些基本任务,这对于任何触发的管道都是常见的。到目前为止,触发按预期工作,这意味着 MainPipeline 触发 DependantPipeline,但是 DependantPipeline 根据我最后的更改跳过所有阶段(构建和测试阶段和 Deploy_DEV 阶段)。它应该仅跳过构建和测试阶段并继续 Deploy_DEV 阶段。

我的目标是仅跳过构建和测试阶段并在 DependantPipeline 上运行开发阶段。另一方面,构建和测试阶段必须仅在 MainPipeline 上运行(并通过)(事实上确实如此)。问题稍后再说,关于 DependantPipeline 和我认为的条件。

# DependantPipeline.yml

trigger: none

resources:
  repositories:
    - repository: Pipelines
      type: git
      name: Pipelines
      ref: test/pipeline
  pipelines:
    - pipeline: triggered-by-main
      project: xxx
      source: 'xxx'
      trigger:
        branches:
          include:
            - test/pipeline

extends:
  template: /templates/pipeline.yml@Pipelines
  parameters:
    variablesTemplate: devops/ew/variables/global_variables.yml@self
    pipelineMode: ${{parameters.pipelineMode}}
    detectChangesFolders: |
      dev=dev
    buildJobs: devops/ew/build_jobs.yml@self
    skipBuildAndTest: true
    devEnvironment: dev
    devVariables: devops/ew/variables/dev_variables.yml@self
    deployEnvironmentTemplate: devops/ew/deploy_environment.yml@self

/templates/pipeline.yml@Pipelines

parameters:
  - name: pipelineMode
    type: string
    displayName: Pipeline Mode
    default: auto
    values:
      - auto
      - main
      - deployment

  - name: buildVariables
    type: string
  - name: deployFeatures
    type: boolean
    default: false
  - name: detectChangesFolders
    type: string
    default: ""
  - name: devEnvironment
    type: string
    default: ""
  - name: devVariables
    type: string
    default: ""
  - name: buildTemplate
    type: string
    default: ""
  - name: buildSteps
    type: stepList
    default: []
  - name: buildJobs
    type: string
    default: ""
  - name: deployEnvironmentTemplate
    type: string
    default: "deployEnvironmentTemplate not provided"
  - name: variablesTemplate
    type: string
    default: ""
  - name: deployParameters
    type: object
    default: []
  - name: ignoreServicePermissions
    displayName: Ignore Service Permissions
    type: boolean
    default: false
  - name: skipBuildAndTest
    displayName: Skip Build and Test
    default: false

stages:
  - stage: Build
    displayName: Build and Test
    condition: and(succeeded(), not(${{parameters.skipBuildAndTest}}))
    pool:
      name: $(agentPool)
    variables: # --> build specific variables
      - ${{ if ne(parameters.buildVariables, '') }}:
          - template: ${{parameters.buildVariables}}
      - job: InitBuild
        displayName: Initialize Build
        steps:
          - template: /Templates/init_build.yml@Pipelines
            parameters:
              detectChangesFolders: ${{parameters.detectChangesFolders}}
          - ${{parameters.buildSteps}}
          - ${{ if ne(parameters.buildTemplate, '') }}:
              - template: ${{parameters.buildTemplate}}
                parameters:
                  pipelineOptions:
                    pipelineMode: ${{variables.pipelineMode}}
                    sourceBranchType: ${{variables['Pipeline.SourceBranchType']}}
                    normalizedSourceBranch: $(Pipeline.NormalizedSourceBranch)
                    isDeploymentPlanned: ${{variables.isDeploymentPlanned}}
                    isDetectChangesEnabled: ${{ne(parameters.detectChangesFolders, '')}}
                    isIgnoreServicePermissions: ${{parameters.ignoreServicePermissions}}
      - ${{ if ne(parameters.buildJobs, '') }}:
          - template: ${{parameters.buildJobs}}
            parameters:
              pipelineOptions:
                pipelineMode: ${{variables.pipelineMode}}
                sourceBranchType: ${{variables['Pipeline.SourceBranchType']}}
                normalizedSourceBranch: $(Pipeline.NormalizedSourceBranch)
                isDeploymentPlanned: ${{variables.isDeploymentPlanned}}
                isDetectChangesEnabled: ${{ne(parameters.detectChangesFolders, '')}}

  - template: /Templates/deploy_environments.yml@Pipelines
    parameters:
      pipelineOptions:
        pipelineMode: ${{variables.pipelineMode}}
        sourceBranchType: ${{variables['Pipeline.SourceBranchType']}}
        normalizedSourceBranch: $(Pipeline.NormalizedSourceBranch)
        isDeploymentPlanned: ${{variables.isDeploymentPlanned}}
        isDetectChangesEnabled: ${{ne(parameters.detectChangesFolders, '')}}
      devEnvironment: ${{parameters.devEnvironment}}
      devVariables: ${{parameters.devVariables}}
      environmentTemplate: ${{parameters.deployEnvironmentTemplate}}
      deployParameters: ${{parameters.deployParameters}}

/模板/deploy_environments.yml@Pipelines

parameters:
  - name: pipelineOptions
    type: object
  - name: devEnvironment
    type: string
    default: ''
  - name: devVariables
    type: string
    default: ''
  - name: environmentTemplate
    type: string
  - name: deployParameters
    type: object
    default: []

stages:
  - ${{ if ne(parameters.devEnvironment, '') }}:
    - stage: Deploy_DEV
      displayName: DEV Environment
      # dependsOn: Build
      condition: succeeded()
      # condition: and(succeeded(), eq('${{parameters.pipelineOptions.pipelineMode}}', 'main'))

      variables: # --> dev specific variables
        - template: ${{parameters.devVariables}}
        - name: environment
          value: ${{parameters.devEnvironment}}
          readonly: true
        - name: env
          value: dev
          readonly: true

      pool:
        name: $(agentPool)
      jobs:
        - template: ${{parameters.environmentTemplate}}
          parameters:
            pipelineOptions: ${{parameters.pipelineOptions}}
            environment: ${{variables.environment}}
            env: ${{variables.env}}
            ${{each param in parameters.deployParameters}}:
              ${{param.key}}: ${{param.value}}  

尝试了很多次都没有达到想要的效果。

我从 Azure DevOps 下载日志,所以也许会有帮助。 日志在构建阶段说:

stages:
- stage: Build
  displayName: Build and Test
  condition: and(succeeded(), not(true))

还在 Deploy_DEV 阶段它说:

- stage: Deploy_DEV
  displayName: DEV Environment
  condition: succeeded()
azure-devops azure-pipelines azure-pipelines-yaml
1个回答
0
投票

构建阶段将被跳过,因为您设置了

skipBuildAndTest: true
,这否定了定义的条件
and( true, not(true) )

将跳过 Deploy_DEV 阶段,因为您已指定前一阶段必须成功:

condition: succeeded()
。这实际上是默认值。

请注意,在阶段之间没有依赖关系的多阶段管道中,假设阶段是连续的,因此相互依赖。由于跳过了 Build 阶段,因此也跳过了 Deploy_DEV 阶段。

如果要评估前一阶段的结果,则需要显式定义关系,以便可以以编程方式使用它。

- stage: Deploy_DEV
  dependsOn:
  - Build
  condition: in( dependencies.Build.result, 'Succeeded', 'Skipped', '')
  ...

在上面,我们检查它是成功还是跳过。检查 '' 的条件是处理手动排队管道且取消选择阶段时的边缘情况。

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