0

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? Thanks!

Shvalb
  • 1,835
  • 2
  • 30
  • 60
  • Ideally you don't want to hardcode the env vars directly into the images and instead you want to pass them when you run them – drum May 19 '21 at 03:33
  • Otherwise look into ARG https://stackoverflow.com/questions/39597925/how-do-i-set-environment-variables-during-the-build-in-docker – drum May 19 '21 at 03:34
  • I see what you mean, but the idea is to put a variable/function in the docker image that would be evaluated only when running in Bitbucket pipelines. so I don't need to pass any arguments to the image, I just would like to have like a macro/variable/placeholder whatever so I can call it at runtime. makes sense? – Shvalb May 19 '21 at 12:25

0 Answers0