gpt4 book ai didi

Azure 管道条件

转载 作者:行者123 更新时间:2023-12-03 06:48:31 25 4
gpt4 key购买 nike

我是 azure 的新手。有人告诉我,我需要提出一个条件:“如果这是一个请求池,那么我们根据内容运行它。如果这是一个构建,那么我们运行所有内容。”正如我所看到的,每个任务在所有这些任务中都已经有一个条件:

condition: eq(dependencies.check.outputs['Check Changes.BE '], 'true')

正如你所看到的,任务的执行取决于BE\FE变量。使用该变量的任务如下所示:

- task: CheckChanges@1
name: CheckChanges
pool: "windows-latest"
inputs:
rules: |
[FE]
**/*.json
**/*.ts
**/*.js
**/*.tsx
**/*.scss
**/*.html
**/*.css

[BE]
**/*.csproj
**/*.cs
**/*.yml
**/*.yaml

以下是需要完成的任务:


- job: Restore BE
displayName: Restore BE
dependsOn: CheckChanges
condition: eq(dependencies.check.outputs['CheckChanges.BE'], 'true')
steps:
- task: Cake@2
displayName: Restore FE and Sitecore modules
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Restore"
verbosity: "Quiet"
Version: "1.3.0"

- job: Restore FE
displayName: Restore FE
dependsOn: CheckChanges
condition: eq(dependencies.check.outputs['CheckChanges.FE'], 'true')
steps:
- task: Cake@2
displayName: Restore FE and Sitecore modules
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Client :: Restore"
verbosity: "Quiet"
Version: "1.3.0"

- job: Build BE
displayName: Build BE
dependsOn: CheckChanges
condition: eq(dependencies.check.outputs['CheckChanges.BE'], 'true')
steps:
- task: Cake@2
displayName: Generate and Build FE and Sitecore
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Build"
verbosity: "Quiet"
arguments: '--BuildConfiguration "Release" --ScSiteUrl "dummy"'
Version: "1.3.0"

- job: Build FE
displayName: Build FE
dependsOn: CheckChanges
condition: eq(dependencies.check.outputs['CheckChanges.FE'], 'true')
steps:
- task: Cake@2
displayName: Generate and Build FE and Sitecore
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Client :: Build"
verbosity: "Quiet"
arguments: '--BuildConfiguration "Release" --ScSiteUrl "dummy"'
Version: "1.3.0"

- job: Unit tests BE
displayName: Unit tests BE
dependsOn: CheckChanges
condition: eq(dependencies.check.outputs['CheckChanges.BE'], 'true')
steps:
- task: Cake@2
displayName: Run Unit tests
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Tests"
verbosity: "Quiet"
Version: "1.3.0"

- job: Unit tests FE
displayName: Unit tests FE
dependsOn: CheckChanges
condition: eq(dependencies.check.outputs['CheckChanges.FE'], 'true')
steps:
- task: Cake@2
displayName: Run Unit tests
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Client :: Tests"
verbosity: "Quiet"
Version: "1.3.0"

我不明白我需要做什么。我的团队负责人只是说:“如果是 Pull 请求,那么我们根据内容运行它。如果是构建,那么我们运行所有内容。”

最佳答案

If it's a Pull Request, then we run it depending on the content. If it's a build, then we run everything.

您可以使用管道预定义变量:Build.Reason来确认管道是否是由 Pull Request 或其他方法触发的。

您可以在条件中添加预定义变量并使用表达式来链接过滤器。

例如:

向 CheckChanges 任务添加条件。

- task: CheckChanges@1
condition: eq(variables['Build.Reason'], 'PullRequest')

向其他作业添加条件:

    - job: Restore BE
displayName: Restore BE
dependsOn: CheckChanges
condition: Or(eq(dependencies.check.outputs['CheckChanges.FE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))

steps:
- task: Cake@2
displayName: Restore FE and Sitecore modules
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Restore"
verbosity: "Quiet"
Version: "1.3.0"

说明:

当 Pipeline 被 Pull Request 触发时,会运行 checkChanges 任务,任务会根据内容运行。

或者,如果管道不是由拉取请求触发的,则管道将运行所有任务。

更详细的信息,您可以引用文档:Condition , Expression , Predefined Variable

关于Azure 管道条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73905447/

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