amazon-ecs-deploy-task-definition icon indicating copy to clipboard operation
amazon-ecs-deploy-task-definition copied to clipboard

Ability to use ENV variables in definition

Open renjinsk opened this issue 5 years ago • 4 comments

When you try to add an environmental variable in image or cluster you get the following error Cluster must match ^[a-zA-Z0-9\-_]{1,255}$, but was $CLUSTER_NAME

Assuming you have the following workflow:

name: Some deployment workflow
on:
  push:
    branches:
      - master

env:
  CLUSTER_NAME: MyClusterName
  ECR_REGISTRY: ecr_registry
  REPO_ONE: repo_one
  REPO_TWO: repo_two
  IMAGE_TAG: sometag
jobs:
  deploy_task:
    name: Deploy The Task
    runs-on: ubuntu-latest
    steps:
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: <key>
          aws-secret-access-key: <secret>
          aws-region: <region>

      - name: Login to AWS ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1

      - name: Download Task Definition
        run: |
          aws ecs describe-task-definition \
          --task-definition <task-def-name> \
          --query taskDefinition > task-definition.json

      - name: Change image 1
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        id: ch-task-def
        with:
          task-definition: task-definition.json
          container-name: <container-name>
          image: $ECR_REPOSITORY/$REPO_ONE:$IMAGE_TAG # This will fail with the message described in issue #49 

      - name: Deploy Task
        uses: aws-actions/amazon-ecs-deploy-task-definition@v1
        with:
          task-definition: ${{ steps.ch-task-def.outputs.task-definition }}
          service: <service-name>
          cluster: $CLUSTER_NAME # This will fail too with the message "Cluster must match ^[a-zA-Z0-9\-_]{1,255}$, but was $CLUSTER_NAME"

As you see in the code block comment, image: will throw the message described in #49 and cluster: the message already posted initially from me. This happens when you use env variables

ps: This is issue was moved to the correct repository. @paragbhingre

renjinsk avatar Feb 15 '21 07:02 renjinsk

This looks to me like a syntax issue in how you are declaring variables.

https://docs.github.com/en/actions/reference/environment-variables

You need to use a specific format for use in actions, for example

{{ env.CLUSTER_NAME }}

mcdermg avatar Apr 14 '21 05:04 mcdermg

@renjinsk Does following suggestion from @mcdermg works for you or you are still facing the error?

paragbhingre avatar Apr 19 '21 23:04 paragbhingre