How to read an environment variable in docker build steps

Hello,

I am trying to figure out how to extract the docker tag from a ‘feature/PRO-123-my-new-feature’ branch as ‘:PRO-123’.

I have already extracted the necessary part and wrote that to a tag.txt file in the following step:

    steps:
  - name: get_drone_tag
    image: debian:buster-slim
    commands:
      - /bin/bash -c "echo ''DRN-$(echo ${DRONE_COMMIT_BRANCH} | awk -F'-' '{print $2}')'' >> tag.txt" 
      - cat tag.txt
      - export DOCKER_TAG=$(cat tag.txt)
      - echo $${DOCKER_TAG}

However, I am unable to use this $${DOCKER_TAG} in my docker build steps. I figured that I need to read the file in each step, but how do use the command to execute - export DOCKER_TAG=$(cat tag.txt)in each docker build step?

These are the steps I am using to build images:

x-base: &base
  <<: *docker
  settings:
    repo: docker-registry
    target: build
x-feature: &feature_config
  settings:
    tag: ${DOCKER_TAG}
  when:
    ref:
     - refs/heads/feature/*
  - name: base-master
    <<: *base
    <<: *feature_config

Thanks for the help!

I’ve found the answer to my question in one of the previous questions.

Hello @ozangungor,

Looks like you were able to get this working by following the other thread, Let me know if you need any further assistance.

Regards,
Harness Support