Variables in drone file

I am trying to push a docker container to different ECR registries based on the branch. Right now I need to specify one build step for each registry with a condition on branch, for example:

pipeline:
    push_dev:
      image: plugins/ecr
      repo: 123456.dkr.ecr.us-east-1.amazonaws.com/app
      when:
        branch: develop
    push_prod:
      image: plugins/ecr
      repo: 789012.dkr.ecr.us-east-1.amazonaws.com/app
      when:
        branch: master

Is there any way to reduce those steps into one and say something like

repo: ${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/app

where ACCOUNT_ID would resolve to the correct account ID based on the branch?
I am thinking something like variable indirection in bash (${!varname}) but couldn’t think of a proper solution without having to embed everything in the drone file.

Hi @gufran, there is no way to do what you are asking at this time.

If there are other steps, I suggest you look at using YAML anchors.

If this is all of your .drone.yml, then a matrix may do what you need.

I used variable to define image name, so it should be fine to define the account id as well.

matrix:
  app_name:
    - app
  develop_account_id:
    - 123456
  production_account_id:
    - 789012

So you can easily define repo in plugin plugins/ecr:

  repo: ${develop_account_id}.dkr.ecr.us-east-1.amazonaws.com/${app_name}

This will work in the near term, but please be advised that #1814 will eventually supersede matrix builds at which point they will be deprecated.

I reviewed https://github.com/drone/drone/issues/1814, but what’s the relationship with matrix?

Could you keep the feature with matrix that I can use with variables? It has been used widely in our drone pipelines. Otherwise, what’s the new way to do it?