The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use the Variable in definitions

Mohan Kona
September 24, 2024

I'm trying to send variable to image in services, bit it seems like the variable is not being accepted and it throws error in the line where image with variable is defined.

Please find the yaml file below

image: image:latest definitions: steps: - step: &udpateEnvVariable name: Populate Environment script: - export ENV=dev - if [ "$FRONTEND_IMAGE" = "release" ]; then export ENV=qa; elif [ "$FRONTEND_IMAGE" = "daily" ]; then export ENV=dev; else export ENV=dev; fi services: frontend: image: name: image_name:$IMAGE options: docker: true pipelines: custom: dummy: - variables: - name: IMAGE default: daily allowed-values: - daily - release - misc - step: *udpateEnvVariable - step: name: Dummy services: - frontend script: - echo "ENV is $ENV" 

 and below is the error thrown

Screenshot 2024-09-24 at 16.24.14.png

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Aron Gombas _Midori_
Community Champion
September 25, 2024

I don't think that the YAML above is valid at all. Validate this with an online validator before anything else.

YAML is very sensitive to indentation and line-breaks, those have important meaning.

Mohan Kona
September 25, 2024

I couldn't paste the code in yaml format, but to make it simple, i'm trying to provide service value as a variable, something like

definitions: 
services:
frontend
:
image:
name: $docker_image

 OR

 

services:
- $docker_image
Aron Gombas _Midori_
Community Champion
September 25, 2024

The variable in this case is a regular Bitbucket pipeline variable?

Also, I don't know, but I guess it is rather likely that variable names are case-sensitive.

Mohan Kona
September 25, 2024

no, the variable here is the user defined one.

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 26, 2024

Hey @Mohan Kona ,

Just adding to @Aron Gombas _Midori_ response, using variables to define image names and services is not yet possible directly in the YAML file.

However, Bitbucket Cloud has recently launched a new feature called Dynamic Pipelines. This feature is designed to make every part of the Pipeline workflow easy to customize and adjust with parameters/variables.

With Dynamic Pipelines, you can use Variable and Deployment APIs to add any custom variables you need at any point in the Pipeline.

You can find more information on how to use these APIs here: Atlassian Community Link.

Thank you, @Mohan Kona !

Patrik S

Like Aron Gombas _Midori_ likes this
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events