pel*_*los 2 azure azure-devops azure-pipelines
如何使 YAML 文件触发和检出分支并运行不同的步骤?
我正在处理 azure 的 YAML 文件,我想在我的主分支中运行某些步骤,并在 QA 分支中运行其他步骤。
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
steps:
- script: ls $(Build.Repository.LocalPath)
displayName: 'printing the ls
Run Code Online (Sandbox Code Playgroud)
我想检查主节点并运行一个步骤,但是如果我想触发 QA 分支上的某些更改,请检查 QA 分支并运行其他步骤。YAML 应该是什么样的?
在每个步骤中,您都可以为condition:每个任务/脚本添加一个:
condition: and(succeeded(), and(eq(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest')))
Run Code Online (Sandbox Code Playgroud)
这将触发 master 分支构建的任务,除非为拉取请求验证触发构建。一个完整的例子:
task: SnykTask@1
condition: and(succeeded(), and(eq(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest')))
displayName: 'Dependency scan'
inputs:
file: xxxxx
test: true
monitor: false
authType: endpoint
endpoint: xxx
severityThreshold: high
failBuild: false
Run Code Online (Sandbox Code Playgroud)
您还可以在 yaml 文件中定义一个阶段。阶段可以包含一组步骤,也可以设置为有条件的:
stages:
- stage: string # name of the stage, A-Z, a-z, 0-9, and underscore
displayName: string # friendly name to display in the UI
dependsOn: string | [ string ]
condition: string variables: { string: string } | [ variable | variableReference ]
jobs: [ job | templateReference]
Run Code Online (Sandbox Code Playgroud)
在最极端的情况下,您可以创建多个 yaml 文件并将它们提交到源代码控制。然后进入 Azure Pipelines UI 并为每个 yaml 文件创建一个管道。使它们完全分离。
也可以看看:
| 归档时间: |
|
| 查看次数: |
1571 次 |
| 最近记录: |