Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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 .....
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
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.