How to use a $BASH_ENV variable as a parameter to a command or when condition

I have a variable determined by a bash script that stores a variable in $BASH_ENV.
I need to use this variable when passing a parameter to a command.
I can pull parameters into variables with << parameters.repository-image >> notation, but the reverse is surely possible.
( Use Environment Variables in Conditional Step ) references a similar need.

Below looks promising. I’ll update with more final results
CORRECTION: this doesn’t work

version: 2.1

    executors:
      default:
        docker:
      - image: circleci/python:3.7.2
commands:
  docker-build-deploy:
    description: "build, tag, and push the docker image built off this code"
    parameters:
      repository-image:
        type: string
    steps:
      - run: echo << parameters.repository-image >>
      - setup_remote_docker
      - docker-sign-in
      - run: docker build --build-arg GIT_SHA=${CIRCLE_SHA1} -t docker-repo/<< parameters.repository-image >>:$DEPLOY_BRANCH .
      - run: docker push docker-repo/<< parameters.repository-image >>:$DEPLOY_BRANCH
      - run: docker tag docker-repo/<< parameters.repository-image >>:$DEPLOY_BRANCH docker-repo/<< parameters.repository-image >>:build-circle-$CIRCLE_BUILD_NUM
      - run: docker push docker-repo/<< parameters.repository-image >>:build-circle-$CIRCLE_BUILD_NUM
jobs:
  api_orion_build:
    executor: default
    working_directory: /home/circleci/build-dir/apis/api-orion
    steps:
      # - setup_remote_docker
      - checkout:
          path: /home/circleci/build-dir
      # - attach_workspace:
      #     at: /tmp/dir
      # - populate-deploy-branch
      # didn't feel like abstracting it, but that's a thing that's actually happening 
      - run: echo "export DEPLOY_BRANCH=ci" >> $BASH_ENV; source $BASH_ENV
      - run: echo "export REPO=ORION" >> $BASH_ENV; source $BASH_ENV
      - run: echo $REPO
      - docker-build-deploy: 
          repository-image: eval "echo $REPO"

There has to be a way to get a circle level variable to be influenced in any way by a bash environment variable, right?

1 Like

With 2.1, It gets complied down before it gets run, so there is no way to get a bash env back up as the parameter doesn’t exist at run time.

I think this feature request is the issue you are hitting https://ideas.circleci.com/ideas/CCI-I-67

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.