gpt4 book ai didi

Azure DevOps YAML Pipeline: 'DeployCode' Stage Skipping Unexpectedly(Azure DevOps YAML管道:“DeployCode”阶段意外跳过)

转载 作者:bug小助手 更新时间:2023-10-24 22:23:14 27 4
gpt4 key购买 nike



Hello Stack Overflow community,
I'm encountering an issue with my Azure DevOps YAML pipeline configuration. Specifically, the DeployCode stage is skipping unexpectedly, even though there are no explicit conditions set for it. I've reviewed my YAML code carefully and couldn't find any obvious reasons for this behavior.

你好,堆栈溢出社区,我遇到了Azure DevOps YAML管道配置的问题。具体地说,DeployCode阶段意外跳过,即使没有为其设置显式条件。我仔细检查了我的YAML代码,找不到导致这种行为的任何明显原因。


Here's a simplified version of my YAML code:

以下是我的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




The DeployInfrastructure stage is conditionally skipped based on the Build.Reason, but there are no conditions or dependencies defined for the DeployCode stage. According to Azure DevOps documentation, it should execute unconditionally as long as the previous stages have completed successfully.

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


I've also checked the build and deployment logs for any errors or issues, but everything seems to be in order.

我还检查了构建和部署日志中是否有任何错误或问题,但似乎一切正常。


Could someone please help me understand why the DeployCode stage is being skipped unexpectedly? Any insights or suggestions for troubleshooting would be greatly appreciated.

有人能帮我解释一下为什么DeployCode阶段会被意外跳过吗?如有任何关于故障排除的见解或建议,我们将不胜感激。


Thank you!

谢谢!


Update:

最新情况:


To provide further clarification, the "DeployCode" stage is skipped only when the "DeployInfrastructure" stage is also skipped, and this occurs specifically when the build status is set to "Scheduled."

为了提供进一步的说明,只有当“DeployInfrastructure”阶段也被跳过时,才跳过“DeployCode”阶段,这特别是当构建状态设置为“Scheduled”时发生的。


更多回答

Each stage implicitly depends on the prior stages succeeding. A skipped stage isn't a successful stage. Look at the documentation for stage conditions, it explains all of this.

每个阶段都隐含地依赖于前几个阶段的成功。跳过的阶段不是成功的阶段。看看阶段条件的文档,它解释了所有这些。

优秀答案推荐


As it is written in documentation 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.



In you case it happens because previous step was not succeeded

在您的情况下,发生这种情况是因为上一步没有成功


You should change it to

您应该将其更改为


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

The new condition works that way that if the pipeline was scheduled then it checks result of the first job, and if not than expects that all jobs finished successfully.

新条件的工作方式是,如果管道已调度,则检查第一个作业的结果,如果不是,则检查所有作业是否成功完成。


enter image description here


更多回答

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