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!

3
  • 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 Commented May 19, 2021 at 3:33
  • Otherwise look into ARG stackoverflow.com/questions/39597925/… Commented May 19, 2021 at 3: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? Commented May 19, 2021 at 12:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.