how to include yaml file in another yaml and overwrite some variable in Bamboo deployment YAML

3.1k views Asked by At

I'm writing bamboo deployment yaml and wants to include another yaml for common functionality and overwrite some of specific variables. eg- I have following yaml But When Import them in Bamboo , it gives me error-

Bamboo YAML import failed: Invalid format of the YAML file: while constructing a mapping in 'reader', line 21, column 3: <<: *map
 expected a mapping or list of mappings for merging, 
but found scalar
 in 'reader', line 17, column 7:    DEV: &map

Please can any one explains what I'm doing wrong here-

#bamboo.yaml
---
version: 2
deployment:
  name: Deploy test
  source-plan: "TEST2"

release-naming:
  next-version-name: release-${bamboo.buildNumber}
  applies-to-branches: false

environments:
  - TEST
  - DEV 
  

DEV: &map
  !include 'deployment/another.yaml'
    
TEST:
  <<: *map
  variables:
    ENV:  test
---
#another.yaml looks like as follows-

triggers:
  - build-success
tasks:
- clean
- script:
    - echo "I’m here"
final-tasks: []
variables: 
  ENV: dev
requirements: []
notifications: []
2

There are 2 answers

0
leadjunk On BEST ANSWER

you can't put an include there, it needs to be mapped to an element, we use it like this:

Dev: &dev-env
  tasks: !include "template/tasks-1.yaml"
  final-tasks: !include "template/tasks-final.yaml"
  variables:
    branch: master
    namespace: prod
    application: xyz
    validate.timeout: 900
  triggers:
    - build-success
QA:
  <<: *dev-env
  variables:
    branch: qa
    application: xyz
    namespace: qa
    validate.timeout: 900
  triggers: []
0
j_slr On

like leadjunk mentioned you can add a !include "file" statement be aware you cant use a include on highlevel more information can be found here: https://community.atlassian.com/t5/Bamboo-questions/how-to-use-bamboo-specs-include-YAML/qaq-p/1112625