Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables passed to local execute are handled incorrectly #385

Closed
nikolaik opened this issue Mar 18, 2020 · 3 comments · Fixed by #389
Closed

Environment variables passed to local execute are handled incorrectly #385

nikolaik opened this issue Mar 18, 2020 · 3 comments · Fixed by #389

Comments

@nikolaik
Copy link

Do you want to request a feature or report a bug?: bug

What is the current behavior?
Environment variables passed with -e to circleci local execute are incorrectly handled. It looks like they are treated as a single value and not being unpacked into the environment of the docker container.

Can you provide an example?

Minimal example config.yml:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/node
    steps:
      - run: env | sort

Running $ circleci local execute -e THIS=1 -e IS=1 -e UNEXPECTED=1:

Output
$ circleci local execute -e THIS=1 -e IS=1 -e UNEXPECTED=1
Docker image digest: sha256:ef0ce77c51b54c3e703a2161cc98963de4dcb59e2d9c97ff9b70d4ce47982993
====>> Spin up Environment
Build-agent version 1.0.12069-0bafdb01 (2019-07-05T21:14:34+0000)
Docker Engine Version: 19.03.8
Kernel Version: Linux 7a6e21fcdf3d 5.3.0-40-generic #32-Ubuntu SMP Fri Jan 31 20:24:34 UTC 2020 x86_64 Linux
Starting container circleci/node
  using image circleci/node@sha256:2afacd3816d81b690586cf8f2e6998e3d7e139ee58ead904b19b3e368e2e08d1

Using build environment variables
  BASH_ENV=/tmp/.bash_env-localbuild-1584549605
  CI=true
  CIRCLECI=true
  CIRCLE_BRANCH=master
  CIRCLE_BUILD_NUM=
  CIRCLE_JOB=build
  CIRCLE_NODE_INDEX=0
  CIRCLE_NODE_TOTAL=1
  CIRCLE_REPOSITORY_URL=git@github.com:nikolaik/docker-python-nodejs
  CIRCLE_SHA1=cfd057c32222bbfad58bec2af48f25d6ee2e6d69
  CIRCLE_SHELL_ENV=/tmp/.bash_env-localbuild-1584549605
  CIRCLE_WORKING_DIRECTORY=~/project

Using environment variables from project settings and/or contexts
  [THIS=**REDACTED**

====>> env | sort
  #!/bin/bash -eo pipefail
env | sort
BASH_ENV=/tmp/.bash_env-localbuild-1584549605
CI=true
CIRCLECI=true
CIRCLE_BRANCH=master
CIRCLE_BUILD_NUM=
CIRCLE_INTERNAL_CONFIG=/.circleci-runner-config.json
CIRCLE_INTERNAL_SCRATCH=/tmp/circleci-389375499
CIRCLE_INTERNAL_TASK_DATA=/.circleci-task-data
CIRCLE_JOB=build
CIRCLE_NODE_INDEX=0
CIRCLE_NODE_TOTAL=1
CIRCLE_REPOSITORY_URL=git@github.com:nikolaik/docker-python-nodejs
CIRCLE_SHA1=cfd057c32222bbfad58bec2af48f25d6ee2e6d69
CIRCLE_SHELL_ENV=/tmp/.bash_env-localbuild-1584549605
CIRCLE_WORKING_DIRECTORY=~/project
DEBIAN_FRONTEND=noninteractive
HOME=/home/circleci
HOSTNAME=1ce9b1465e96
LANG=C.UTF-8
NODE_VERSION=13.10.1
PATH=/home/circleci/.local/bin:/home/circleci/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/home/circleci/project
SHLVL=1
SSH_AUTH_SOCK=/tmp/circleci-389375499/ssh_auth_sock
YARN_VERSION=1.22.0
[THIS=1,IS=1,UNEXPECTED=1]
_=/usr/bin/env
Success!

What is the expected behavior?
I expect the env vars to be unpacked one by one and env should output something like:

...
THIS=1
IS=1
UNEXPECTED=1
...

Which version of the CLI and OS are you using?

0.1.6949+d951526
$ circleci diagnostic

---
CircleCI CLI Diagnostics
---
Debugger mode: false
Config found: /home/nikolark/.circleci/cli.yml
API host: https://circleci.com
API endpoint: graphql-unstable
OK, got a token.
Trying an introspection query on API... 
Ok.
Hello, Nikolai

Did this work in previous versions?
Yup! If remembering correctly, I have previously been able to pass env vars to jobs.

@alexfornuto
Copy link
Contributor

Additionally, passing single vars is also failing, for example:

  BASH_ENV=/tmp/.bash_env-localbuild-1585172471
  CI=true
  CIRCLECI=true
  CIRCLE_BRANCH=local-testing
  CIRCLE_BUILD_NUM=
  CIRCLE_JOB=build
  CIRCLE_NODE_INDEX=0
  CIRCLE_NODE_TOTAL=1
  CIRCLE_REPOSITORY_URL=git@github.com:pantheon-systems/documentation.git
  CIRCLE_SHA1=0abdec97ece0874aa5c6ee34649fa5d6682cd474
  CIRCLE_SHELL_ENV=/tmp/.bash_env-localbuild-1585172471
  CIRCLE_WORKING_DIRECTORY=~/build

Using environment variables from project settings and/or contexts
  [GITHUB_API=**REDACTED**

$GITHUB_API isn't found by the process using it, and I wonder if it's going in as $[GITHUB_API

@kunimitaiyoh
Copy link

Same issue here.

Only first environment variable could be passed with command like circleci local execute --job job -e FOO=1 -e BAR=2 -e BAZ=3 and it seems that the name of the environment variable becomes [FOO instead of FOO.

@tquach
Copy link

tquach commented Mar 30, 2020

This affects the --volume flag as well. Passing in additional mounts causes the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants