0

We are using multiple Azure pipelines to deploy services, using YAML code as definitions for the pipelines.

Now each of the pipelines may run their jobs in build containers defined in the resources section of the YAML file:

resources:
  containers:
  - container: some-container
    image: myacr.azurecr.io/some-container:latest
    endpoint: myacr
  - container: another-container
    image: myacr.azurecr.io/another-container:latest
    endpoint: myacr
  - ...

Now, as multiple pipelines use these containers, managing these becomes tedious, as their number grows.

Is there some way to include these in a template or somehow include these in the YAML file?

I tried to use a template like this:

pipeline-1.yml:

resources:
  containers:
  - template: containers.yml

containers.yml:

containers:
- container: some-container
  image: myacr.azurecr.io/some-container:latest
  endpoint: myacr
- container: another-container
  image: myacr.azurecr.io/another-container:latest
  endpoint: myacr

But the pipeline runner does not accept that, it emits "Unexpected value: template".

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
  • How about the issue? Does the answer below resolved your question, If yes, you could accept it as an answer, so it could help other community members who get the same issues and we could archive this thread, thanks. If not, please let us know if you would like further assistance – Felix Mar 29 '21 at 01:48

1 Answers1

0

According the doc: Resources: containers, We do not support the keywords 'template' in the container resource. And also, we recommend you can create a suggestion ticket on the Developer Community:https://developercommunity.visualstudio.com/report?space=21&entry=suggestion

Felix
  • 1,104
  • 3
  • 6
  • Okay. But then, what would be an alternative? – MC Emperor Mar 10 '21 at 07:50
  • Hi MC, We do not have the workaround to solve this. We recommend you add the container resource into each yaml file. By the way, if it is possible, you can try to move your other code into the template yaml file, and use the 'extends'. But this might need to change a lot, because we can not add any steps after the 'extends'. Refer doc: https://learn.microsoft.com/en-us/azure/devops/pipelines/security/templates?view=azure-devops#use-extends-templates and https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#extend-from-a-template-with-resources – Felix Mar 10 '21 at 08:15