Sourcing $BASH_ENV in an Alpine docker image



I am trying to build a docker image inside a circleci container, I am using the docker:edge-git image based on alpine as explained in the tutorial How to build a docker image in CircleCI 2.0

This is the relevant part of my config.yml:

version: 2
      - image: docker:edge-git
    working_directory: /app
      - checkout
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache bash
      - run: echo 'export PATH="/app/make:$PATH"' >> $BASH_ENV
      - run: |
          echo $PATH
      - run: |
          source $BASH_ENV
          echo $PATH

and see the result (screenshot taken with other values for $PATH, but still relevant):

As said in this topic : Injecting custom environment variables when running locally via CircleCI CLI apparently sourcing does not works for images that have no bash installed, what can I do to fix this without needing to source my file prior to each RUN command ?


Just set PATH to that string from the last run step


not sure I get what to do here ? echo 'export PATH="/app/make:$PATH"' >> $BASH_ENV already updates PATH


I thought the point of your post here was it’s not working for Alpine images. Define the PATH as a string, not with $PATH. Each Docker image has a $PATH defined so just echo it and copy/paste it into your config. Easy stuff.


My point is that I don’t want to specify path manually, I want only to update the existing $PATH on alpine linux distribution with a custom dir, as marked here, but that behaviour seem to not work for alpine images (see this comment.

My question now is: is this a bug and will it be fixed eventually ? Because I have a workaround which is sourcing manually the $BASH_ENV before each run, but it feels dirty.


We’re not the maintainers of sh, I don’t know how you anticipate we fix this. $BASH_ENV is a bash thing.


Thx Rohara, I am not at all a bash/shell developer, I thought BASH_ENV is some circle-ci logic for updating the PATH of the container, my bad.

I will keep sourcing the file until something better comes up :wink: