[duplicate] Drone docker runner unable to use tags from environment variables

Hello, I’m having issue with using environment variables with tags.
The problem is that environment variables are not populated to tags in the docker plugin.
Here you can find example testing code:

kind: pipeline
type: docker
name: test run

environment:
  IMAGE_VERSION: 2

steps:
- name: test1
  image: plugins/ecr
  environment:
    IMAGE_VERSION: 1
  settings:
    access_key:
      from_secret: aws_key_push
    secret_key:
      from_secret: aws_secret_push
    region: eu-west-1
    repo: YYYYYYYYY
    registry: XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com
    dockerfile: Dockerfile
    tags:
      - $IMAGE_VERSION
    build_args_from_env:
      - IMAGE_VERSION

- name: test2
  image: plugins/ecr
  settings:
    access_key:
      from_secret: aws_key_push
    secret_key:
      from_secret: aws_secret_push
    region: eu-west-1
    repo: YYYYYYYYY
    registry: XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com
    dockerfile: Dockerfile
    tags:
      - ${IMAGE_VERSION}
    build_args_from_env:
      - IMAGE_VERSION

- name: test3
  image: plugins/ecr
  settings:
    access_key:
      from_secret: aws_key_push
    secret_key:
      from_secret: aws_secret_push
    region: eu-west-1
    repo: YYYYYYYYY
    registry: XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com
    dockerfile: Dockerfile
    tags:
      - $${IMAGE_VERSION}
    build_args_from_env:
      - IMAGE_VERSION

- name: Join steps
  image: public.ecr.aws/amazonlinux/amazonlinux:latest
  depends_on: [ test1, test2, test3 ]
  commands:
    - echo "works?"

the result of each task is:

  • test1
    Successfully tagged 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39:latest /usr/local/bin/docker tag 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39 XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY:$IMAGE_VERSION
    Error parsing reference: "XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY:$IMAGE_VERSION" is not a valid repository/tag: invalid reference format
    time="2021-02-25T08:04:34Z" level=fatal msg="exit status 1"
    
  • test2
    Successfully tagged 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39:latest
    /usr/local/bin/docker tag 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39 XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY:latest
    /usr/local/bin/docker push XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY:latest
    The push refers to repository [XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY]
    e84e86a2ce7e: Preparing
    e84e86a2ce7e: Pushed
    latest: digest: sha256:e64d3168ccb3cbffd9bce7bd86b00bc551e8d355c3733b3ecd7989478d0bbb1d size: 529
    /usr/local/bin/docker rmi 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39 Untagged: 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39:latest
    
  • test3
    Successfully tagged 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39:latest /usr/local/bin/docker tag 12dcb243e1a2afbd6266bfe8c24d8ec8d0cede39 XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY:${IMAGE_VERSION}
    Error parsing reference: "XXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/YYYYYYYYY:${IMAGE_VERSION}" is not a valid repository/tag: invalid reference format
    time="2021-02-25T08:04:34Z" level=fatal msg="exit status 1"
    

As you can see each job failed. First and third one wasn’t able to read variable at all. Second one gave empty value to tags instead of exact value.

I solved this issue by using additional step with creating .tags file, but I believe that this problem should be fixed anyway.

See http://discuss.harness.io/t/using-environment-variables-in-plugin-settings/7598/2

The syntax in your example is not supported. The plugin you are using (and most plugins) are written in Go and the strings are Go string literals. The environment $variable syntax in your example would only work with a bash string, and would need to be run through a bash interpreter, which is not the case given the plugin is a Go program.