Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

bamboo-specs parsing variables in yaml file

Hello,

i was looking for a way to parse variables in YAML files, in order to use some kind of template and just change 2 or 3 specific parameters

for example, i have 3 environments (DEV, PREPROD, PROD)  which should use same YAML file Template,  and will just need to replace environment itself

Example:

---
version: 2
deployment:
  name: STATUS
  source-plan: "ROCKET-STATUS"
release-naming:
  next-version-name: "Run"

environments:
  - DEV

DEV:
  tasks:
    - script:
        interpreter: shell
        scripts:
        - echo dev

 

 

i have same for PREPROD and PROD

 

i would like to put in beggining of the file  STAGE=DEV    and stage=dev

 

and then just use $STAGE or $stage

 

please help

2 answers

1 vote
Jimmy Seddon Community Leader May 29, 2020

Hi @Alexander Gorshtein,

I've been wanting the same type of thing.  The best I was able to do is plan based variables, but that I mean I did this:

---
version: 2

variables:
projectname: MyProject

plan:
project-key: Test
key: MP
name: My Test Project

Then further down I'm able to use that:

Build:
key: BLD
tasks:
- clean
- script:
interpreter: powershell
scripts:
- Find-Module -Name "MyCompany.MyModule" | Install-Module
- Build-Application -ProjectFile "${bamboo.projectname}.csproj"

It's not perfect, but it allows you to use a common variable name that you can substitute near the beginning of each plan and you can reuse the same variable name in each plan.

Also, I think you might be interested in voting for and commenting on this issue in Atlassian's public defect/feature request tracker: https://jira.atlassian.com/browse/BSERV-10945

It looks like it's requesting something similar that you might be able to provide your specific use case on in the comments.

I hope that helps a little bit.  Sorry there isn't a good answer to this question.

-Jimmy

huh, thanks alot

 

but when you use:

variables:
projectname: MyProject

and then: 

"${bamboo.projectname}.csproj"

 

it would look only within the plan?

 

because for example i have 3 different plans per stage, will include the variable thing, which you show, then ill have same deployment template (will use variables) and it would work?

Jimmy Seddon Community Leader May 29, 2020

Just to make sure I'm using the same terminology you are.  Build Plans contain Stages.  Are you trying to use the same variable for multiple stages within the same plan?

If so, I don't believe YAML specs offers that type of variable substitution.

One other option that you might want to consider is using Java specs instead (not sure how comfortable you are with Java) but that type of variable substitution is 100% available in Java specs.  I've ended up using a mixture of both depending on how complex my build plans are.

YAML is great for simple one or two step build plans but Java is better for the more complex items.

-Jimmy

i have yaml file for each stage, but want each yaml to be some kind of template, and in top of it to describe variables

 

in BASH and Python it will work, but here, not sure

 

regarding your variable, i think this way it goes into bamboo global variables, so i think it will not work

 

i need variable to be set only within yaml file

--- Example is in a whole nother playground buddy one i developed and still developing so i understand you need to change the 3 enviroments from being 1 to 3. the task isnt impossible but you need the right people on the case etc,. workers.

also the echo may be your problem just like echo hello world

for your task in your sysytem

dont pay attention to the echo, its different script:

 

ansible-playbook -i inventory/dev    start_websphere.yml     and etc.....

 

i want to put variable   ansible-playbook -i inventory/$stage  start_websphere.yml 

in order it automatically recognize environment

 

so also it will be replaced on other parameters,   example what i thought:

 

 ###  you put variables at the top, and below template is same everywhere so  for easier modifying

STAGE=DEV   

stage=dev

---
version: 2
deployment:
name: STATUS
source-plan: "ROCKET-STATUS"
release-naming:
next-version-name: "Run"

environments:
- $STAGE

$STAGE:
tasks:
- script:
interpreter: shell
scripts:
- ansible-playbook -i inventory/$stage  start_websphere.yml 

that kinda makes sense considering you have no other options

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 7.2 is here!

I'm happy to announce that Bamboo 7.2 has been released and it’s overflowing with awesome new features. This will be the last major Server release before the launch of Bamboo DC. Bamboo logs We...

450 views 5 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you