How to read an environment variable in docker build steps


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:

  - name: get_drone_tag
    image: debian:buster-slim
      - /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
    repo: docker-registry
    target: build
x-feature: &feature_config
    tag: ${DOCKER_TAG}
     - 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.

Harness Support