我有多个 Azure DevOps 管道文件,其中包含许多阶段,如下所示:
...
- stage: 'qa'
dependsOn:
- dev
condition: |
and
(
condition1,
condition2,
...,
startswith(variables['Build.SourceBranch'], 'refs/heads/development')
)
# This needs to stay the same
- stage: 'uat'
dependsOn:
- dev
condition: |
and
(
condition1,
condition2,
...,
startswith(variables['Build.SourceBranch'], 'refs/heads/development')
)
...
现在我们正在将所有这些文件更新为新的部署策略,我需要更改两件事 - dependentOn 子句和refs/heads/development
条件中的源分支 - 但仅限于 qa 阶段。
结果应该是这样的
...
- stage: 'qa'
dependsOn:
- build
condition: |
and
(
condition1,
condition2,
...,
startswith(variables['Build.SourceBranch'], 'refs/heads/main')
)
# This needs to stay the same
- stage: 'uat'
dependsOn:
- dev
condition: |
and
(
condition1,
condition2,
...,
startswith(variables['Build.SourceBranch'], 'refs/heads/development')
)
...
我能够很容易地完成第一部分 - 我知道该数组中始终只有一个项目。所以这会起作用sed "/stage: 'qa'/{ n; n; s/dev/build/g }" pipeline.yaml
但第二部分更难,可能有多个条件,我不知道要跳过多少行。
有没有办法告诉sed
只替换文件的一部分中的字符串,比如说字符串出现位置下方的 4 到 10 行stage: 'qa'
?