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

can't seem to get VARIABLE to work in ~/.gitlab-ci-local/.env #1165

Closed
justinTM opened this issue Mar 28, 2024 · 4 comments
Closed

can't seem to get VARIABLE to work in ~/.gitlab-ci-local/.env #1165

justinTM opened this issue Mar 28, 2024 · 4 comments

Comments

@justinTM
Copy link

justinTM commented Mar 28, 2024

Minimal .gitlab-ci.yml illustrating the issue

my-job:
  script:
    if [ -n "$CI_JOB_TOKEN" ]; then echo "can't find CI_JOB_TOKEN!" && exit 1; fi
# ~/.gitlab-ci-local/.env
VARIABLE="CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN"
GCL_VARIABLE="CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN"
CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN

export VARIABLE="CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN"
export GCL_VARIABLE="CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN"
export CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN
$ echo $GITLAB_ACCESS_TOKEN
glpat-XXXXXXXXX
$ gitlab-ci-local \        
    --variable DOCKER_HOST="" --variable RUNNER_REGISTRATION_TOKEN=$RUNNER_REGISTRATION_TOKEN \
    --variable CI_ENVIRONMENT_STAGE=dev --variable CI_PROJECT_ID=$CI_PROJECT_ID \
    --volume ~/.aws:/root/.aws --volume ~/.terraform.d:/root/.terraform.d \
    --privileged --mount-cache \
    'my-job'
Using fallback branch data
parsing and downloads finished in 23 ms
my-job starting shell (test)
my-job $ if [ -n "$CI_JOB_TOKEN" ]; then echo "can't find CI_JOB_TOKEN!" && exit 1; fi
my-job > can't find CI_JOB_TOKEN!
my-job finished in 13 ms  FAIL 1 

Expected behavior
nothing is printed -- job succeeds.

Host information
macOS
gitlab-ci-local 4.47.0

Containerd binary
Are you using docker or podman, or any other relevant containerization tool.

Additional context
Add any other context about the problem here.

@justinTM
Copy link
Author

ah i see... it is not compatible with setting any variables via CLI. when i remove all --variable flags in the command, it succeeds. so definitely a bug. i guess no one uses this feature lol!

@justinTM
Copy link
Author

it also apparently can't handle multiple VARIABLE flags inside dotenv file :/

@justinTM
Copy link
Author

justinTM commented Mar 28, 2024

also, when you specify multiple variables inside a single VARIABLE, it only applies the second one (skipping the first):

# ~/.gitlab-ci-local/.env
VARIABLE="CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN;DOCKER_HOST='xxxxx'"
gitlab-ci-local 'my-job'
Using fallback branch data
parsing and downloads finished in 21 ms
my-job starting shell (test)
my-job $ if [ -n "$CI_JOB_TOKEN" ]; then echo "can't find CI_JOB_TOKEN!" && exit 1; fi
my-job > can't find CI_JOB_TOKEN!
my-job finished in 11 ms  FAIL 1 

 FAIL  my-job
  > can't find CI_JOB_TOKEN!

putting a space instead of ; makes it work for the first variable but not for the second:

# ~/.gitlab-ci-local/.env
VARIABLE="CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN DOCKER_HOST='xxxxx'"
gitlab-ci-local 'my-job'
Using fallback branch data
parsing and downloads finished in 22 ms
my-job starting shell (test)
my-job $ if [ -n "$CI_JOB_TOKEN" ]; then echo "can't find CI_JOB_TOKEN!" && exit 1; fi
my-job $ if [ -n "$DOCKER_HOST" ]; then echo "can't find DOCKER_HOST!" && exit 1; fi
my-job > can't find DOCKER_HOST!
my-job finished in 12 ms  FAIL 1 

 FAIL  my-job
  > can't find DOCKER_HOST!

@firecow
Copy link
Owner

firecow commented Mar 28, 2024

#992 Yeah, we are tracking the issue here

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

No branches or pull requests

2 participants