如何调用包含"resources"的 Azure 管道模板?



由于某些原因,我希望我的A.yml从其他存储库调用另一个B.yml。管道A被认为是一个"空"管道,它的工作基本上是调用管道B,而B完成了真正的工作。但B不只是步骤,它包含了所有的细节,它还包括"资源"。

我是这样做的:

管道:

trigger:
- main
resources:
repositories:
- repository: script
type: github
name: xxx/script
ref: refs/heads/main
endpoint: smartracks
steps: **<---- What should I put ?**
- template: B.yml@script

管道B:

resources:
repositories:
- repository: rcu-service
type: github
name: abc/rcu-service
ref: refs/heads/main
endpoint: test
jobs:
- job: OpenEmbedded_Build_And_Export
steps:
- checkout: rcu-service
- script: |
......

如果我排除了资源"在管道B中,它将成功(需要将这些资源添加到管道A中)。但是,一旦我将资源包含在管道B中,它就会失败,并显示以下消息:

B.yml@script(Line: 1, Col: 1): Unexpected value 'resource'
B.yml@script(Line: 24, Col: 1): Unexpected value 'jobs'
在管道A中,这是我调用管道B的方式,我使用步骤,但似乎行不通。

steps: **<---- What should I put ?**
- template: B.yml@script

我尝试过阶段,工作,但都失败了。

所以,我在想我该怎么办?请教我,谢谢。

Azure pipeline支持四种模板:

  • <
  • 变量/gh>

它不支持resources,你需要把resources放在你的A.yml。

https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&标签=模式% 2 cparameter-schema # template-references

假设您要展开模板,以便它显示在您放置- template:...的文件中。在本例中,您将使用

steps:
- jobs:
...

这不起作用,因为模式要求步骤成为作业的一部分。

jobs: 
- template: B.yml@script

stages:
- stage: stageName
displayName: "my stage"
jobs:
- template: B.yml@script

最新更新