2

I am trying to build reusable pipeline and basic architecure is -

I have multiple application repositories (appRepo1, appRepo2,..) and all of them having their yaml pipeline for example (appRepo1.yml, appRepo2.yml,..)

These app pipelines will call common pipeline(common.yml) which is in different repository (CommonRepo).

The common pipeline(common.yml) will be responsible to call other template pipeline(Scanning.yml in ScanRepo,Infra.yml in InfraRepo ) which are in different repositories.

Basically I want to keep application's pipeline YAML to be very thin

. I don't want to call different templates of different repository from application pipeline. Instead Common template yaml of common repository should templates from various repository.

appRepo.yml

   name: "$(BuildDefinitionName)_$(SourceBranchName)_$(date:yyyyMMdd)$(rev:.r)"

trigger: none
resources:
  repositories: 
  -  repository: CommonPipeline
     type: GIT
     name: CommonPipeline
     ref: "dev"
  
extends:
 template: common.yml@CommonPipeline
     

common.yml in CommonRepo

resources:
  repositories: 
    - repository: InfraRepo
      type: GIT
      name: "InfraRepo"
      ref: "dev"
    - repository: ScanRepo
      type: GIT
      name: "ScanRepo"
      ref: "dev"


variables:
        - template: Pipeline/vars/app-var.yaml

stages:
        - template: Pipeline/stages/scanning.yml@ScanRepo
        - template: Pipeline/stages/infra.yml@InfraRepo 

Is it possible to put (resources -> repositories) in both appRepo.yml and common.yml ? I am getting an error when I run appRepo1 pipeline(appRepo.yml) if i keep resources section in common.yml.

Error is -

Internal error reading the template. Expected a scalar,a sequence,or a mapping

F11
  • 3,703
  • 12
  • 49
  • 83
  • Your YAML is malformed. Is this exactly how it's formatted in your repository? If so, carefully check your YAML for indentation issues. – Daniel Mann Mar 13 '23 at 23:08
  • @DanielMann Fixed those, my question is can we keep (resources -> repositories) in both root yaml & template yaml? If i remove resources section from template yaml, no error but if i put resources section,i am getting error – F11 Mar 14 '23 at 01:30

1 Answers1

0

No, it's not possible to have resources > repositories in both root and template YAML due to the YAML schema limitations in Azure Pipelines. This would cause a duplication of the resources section within the compiled YAML pipeline which is not valid.

So, you would need to add the repositories in the appRepo.yml template. If you are worried about exploitation of the templates, you can check Security through templates

Also check out how you can enhance pipeline security using resources

Sibtain
  • 1,436
  • 21
  • 39
  • I want to have application pipelines having minimum code. application pipelines just to need to call common pipelines which does all the various job. – F11 Mar 14 '23 at 18:56
  • 1
    Your idea of using `common.yml` is just fine but having the other templates in different repos doesn't look right. You could just keep `scanning.yml` and `infra.yml` in the `CommonPipeline` repository. Think of it as a centralized repo that's hosts all your generic templates that might have stages, steps or jobs. – Sibtain Mar 14 '23 at 19:10