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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

I need to pass variable to task-definition on Deploy to AWS-ECS

Deleted user Jul 22, 2022

I need to change ne name of IMAGE dynamically int the task definition. I tried in many ways but without success.

 

thats my pipe:

- step:

name: Push
image: atlassian/pipelines-awscli
# Pass the Docker service with 7 GB
services:
- docker-7g
oidc: true
# Raise the Step limit from 4 GB to 8 GB.
size: 2x
script:
- TAG=$BITBUCKET_COMMIT
- export AWS_REGION=****
- export AWS_ROLE_ARN=$AWS_ROLE_ARN_1
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- IMAGE="**.dkr.ecr.us-east-1.amazonaws.com/am/account-manager:${TAG}"  <= IMAGE
- eval $(aws ecr get-login --no-include-email --region us-east-1| sed 's;https://;;g')
- docker build -t $IMAGE .
- docker push $IMAGE

 

==>   this step above works fine. The image is being sent to ECR with BITBUCKET_COMMIT as a TAG

 

- step:
name: deploy
image: atlassian/default-image:2
services:
- docker
oidc: true
script:
- TAG=$BITBUCKET_COMMIT
- export IMAGE="*****.dkr.ecr.us-east-1.amazonaws.com/am/account-manager:${TAG}"
- envsubst $IMAGE < pipeline/task-definition-template.json > pipeline/task-definition.json
- pipe: atlassian/aws-ecs-deploy:1.6.2
variables:
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
AWS_OIDC_ROLE_ARN: $AWS_OIDC_ROLE_ARN_1
CLUSTER_NAME: 'am-production-Cluster-GBJBMXmKQYm3'
SERVICE_NAME: 'am-production-account-manager-Service-0lU6qXwcHbOr'
TASK_DEFINITION: 'pipeline/task-definition.json'  <=  Here is where i need a solution to change the TAG int the parameter IMAGE whit the variable that i created.
services:
- docker

 

task-definition.json

 

something esle before .....

],
"image": "",  <== <=  Here is where i need a solution to change the TAG int the parameter IMAGE whit the variable that i created.
"name": "account-manager"
}
],
.......something esle  after.....

 

 

 

2 answers

1 accepted

2 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jul 28, 2022

Hello @[deleted] ,

Thank you for reaching out to Atlassian Support.

Looking at the YML file you shared, it seems like you already tried to use envsubs, and this would be my suggestion. From my understanding, you are building the image name and exporting it to a variable named $IMAGE, and as long as the variable $IMAGE is referenced in the file pipeline/task-definition-template.json , the envsubst command should work.

Just one thing to note is that you need to pass the variables to be replaced in single quotes, and envsubst just works for variables exported ( e.g. export MYVAR=123).

So, for example, if your pipeline/task-definition-template.json is like below :

[...]

{
"image"
"$IMAGE",  <== <=  Here is where i need a solution to change the TAG int the parameter IMAGE whit the variable that i created.

"name""account-manager"

}

[....]

Using the below envsubst command should work to replace any occurrence of $IMAGE in the file, by the value of that environment variable : 

envsubst '$IMAGE' < pipeline/task-definition-template.json > pipeline/task-definition.json

And then you can use the pipeline/task-definition.json as the pipe's task-definition.

You can give it a try with the above syntax and let us know how it goes. If it still not working, I would recommend adding a command to print the content of the file created from envsubst to confirm the variable was indeed replaced :

- cat pipeline/task-definition.json

Let me know in case you have any questions.

Thank you, @[deleted] .

Kind regards,

Patrik S

0 votes
Deleted user Aug 01, 2022

hey Patrick,

 

Thanks. It Worked.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events