gpt4 book ai didi

Azure DevOps YAML 管道 : 'DeployCode' Stage Skipping Unexpectedly

转载 作者:行者123 更新时间:2023-12-02 08:11:06 25 4
gpt4 key购买 nike

Stack Overflow 社区您好,我的 Azure DevOps YAML 管道配置遇到问题。具体来说,即使没有为其设置明确的条件,DeployCode 阶段也会意外跳过。我仔细检查了我的 YAML 代码,没有找到导致此行为的任何明显原因。

这是我的 YAML 代码的简化版本:

trigger:
branches:
include:
- develop
- master
- feature/x

schedules:
- cron: '30 * * * *'
displayName: Every hour at 30th minute...
branches:
include:
- develop
- master
- feature/x
always: true

pr: none
pool:
vmImage: ubuntu-20.04

variables:
BRANCH_NAME: ${{ replace(variables['Build.SourceBranch'], 'refs/heads/', '') }}

${{ if in(variables['BRANCH_NAME'], 'develop', 'feature/x') }}:
TF_ENVIRONMENT: test
${{ elseif eq(variables['BRANCH_NAME'], 'x') }}:
TF_ENVIRONMENT: x

RESOURCE_GROUP: '${TF_ENVIRONMENT}x-rg'
STORAGE_ACCOUNT_NAME: '${TF_ENVIRONMENT}x'
CDN_ENDPOINT_NAME: '${TF_ENVIRONMENT}x'
CDN_PROFILE_NAME: '${TF_ENVIRONMENT}x-profile'
AZURE_SUBSCRIPTION: 'Your-Subscription-Name-Here'
AZURE_SUBSCRIPTION_ID: 'Your-Subscription-ID-Here'

stages:
- stage: DiagnosticJob
jobs:
- job: DiagnosticJob
steps:
- script: |
echo "Build Reason: $BUILD_REASON"
displayName: Print Build Reason

- stage: DeployInfrastructure
condition: ne(variables['Build.Reason'], 'Schedule')
jobs:
- job: ConditionalInfrastructureDeployment
steps:
- script: |
echo "BRANCH_NAME: $BRANCH_NAME"
echo "TF_ENVIRONMENT: $TF_ENVIRONMENT"
echo "AZURE_SUBSCRIPTION: $AZURE_SUBSCRIPTION"
echo "AZURE_SUBSCRIPTION_ID: $AZURE_SUBSCRIPTION_ID"
displayName: Print Expression Result
#infrastructure deployment steps here

- stage: DeployCode
jobs:
- job: DeployWebsite
steps:
# code deployment steps here

根据 Build.Reason 有条件地跳过 DeployInfrastruct 阶段,但没有为 DeployCode 阶段定义条件或依赖项。根据Azure DevOps文档,只要前面的阶段成功完成,它就应该无条件执行。

我还检查了构建和部署日志是否有任何错误或问题,但一切似乎都按顺序进行。

有人可以帮我理解为什么 DeployCode 阶段会被意外跳过吗?任何有关故障排除的见解或建议将不胜感激。

谢谢!

更新:

为了提供进一步的说明,仅当“DeployInfrastruct”阶段也被跳过时,“DeployCode”阶段才会被跳过,并且这种情况特别是在构建状态设置为“已计划”时发生。

最佳答案

正如文档中所写的那样 here :

You can specify the conditions under which each stage, job, or step runs. By default, a job or stage runs if it doesn't depend on any other job or stage, or if all of the jobs or stages it depends on have completed and succeeded. This includes not only direct dependencies, but their dependencies as well, computed recursively. By default, a step runs if nothing in its job has failed yet and the step immediately preceding it has finished. You can customize this behavior by forcing a stage, job, or step to run even if a previous dependency fails or by specifying a custom condition.

在您的情况下,发生这种情况是因为上一步不是 succeeded

你应该将其更改为

stages:
- stage: DiagnosticJob
jobs:
- job: DiagnosticJob
steps:
- script: |
echo "Build Reason: $BUILD_REASON"
displayName: Print Build Reason

- stage: DeployInfrastructure
condition: ne(variables['Build.Reason'], 'Schedule')
jobs:
- job: ConditionalInfrastructureDeployment
steps:
- script: |
echo "BRANCH_NAME: $BRANCH_NAME"
echo "TF_ENVIRONMENT: $TF_ENVIRONMENT"
echo "AZURE_SUBSCRIPTION: $AZURE_SUBSCRIPTION"
echo "AZURE_SUBSCRIPTION_ID: $AZURE_SUBSCRIPTION_ID"
displayName: Print Expression Result
#infrastructure deployment steps here

- stage: DeployCode
dependsOn:
- DiagnosticJob
- DeployInfrastructure
condition: or(and(succeeded(), ne(variables['Build.Reason'], 'Schedule')), and(eq(variables['Build.Reason'], 'Schedule'), dependencies.DiagnosticJob.result == 'Succeeded'))
jobs:
- job: DeployWebsite
steps:
# code

新条件的工作方式是,如果管道已计划,则它会检查第一个作业的结果,如果没有,则预计所有作业均成功完成。

enter image description here

关于Azure DevOps YAML 管道 : 'DeployCode' Stage Skipping Unexpectedly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77076515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com