How to set environment variable when creating a Docker image

  bitbucket-pipelines, dockerfile

I’m pretty new to Docker and I have the following requirement:

I need to create a new Docker image (via Dockerfile) that used as FROM in a Bitbucket Pipelines
and this image sets an environment variable that captures current Git feature-branch name.

Here is my attempt:

FROM maven:3.8.1-openjdk-8-slim


ENV GIT_FEATURE_BRANCH_NAME RUN (git rev-parse --abbrev-ref HEAD)

Will this work? I would like it to be accessed from bitbucket_pipelines.yml file by doing $GIT_FEATURE_BRANCH_NAME

Any thoughts on that?

Source: Dockerfile Questions