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

gitlab-ci-local overwrites a pre-defined variable from gitlab-ci.yml #1465

Open
BenediktBertsch opened this issue Jan 7, 2025 · 4 comments · May be fixed by #1466
Open

gitlab-ci-local overwrites a pre-defined variable from gitlab-ci.yml #1465

BenediktBertsch opened this issue Jan 7, 2025 · 4 comments · May be fixed by #1466

Comments

@BenediktBertsch
Copy link

Minimal .gitlab-ci.yml illustrating the issue

---
test:
  stage: deploy
  variables:
    CI_PROJECT_DIR: "TEST_DIRECTORY"
  script:
    - |
      echo "CI_PROJECT_DIR: $CI_PROJECT_DIR"

Expected behavior
The expected behavior should be that the CI_PROJECT_DIR variable is overwritten by the job's variable.
Expected output should be:
"test > CI_PROJECT_DIR: TEST_DIRECTORY" instead I get "test > CI_PROJECT_DIR: /gcl-builds"

Host information
Ubuntu
gitlab-ci-local 4.56.2

Containerd binary
I'm using docker.

Thank you for this great tool.

@BenediktBertsch BenediktBertsch changed the title gitlab-ci-local doesnt overwrite a pre-defined variable from gitlab-ci.yml gitlab-ci-local overwrites a pre-defined variable from gitlab-ci.yml Jan 7, 2025
@ANGkeith
Copy link
Collaborator

ANGkeith commented Jan 10, 2025

what exactly are you trying to achieve here by overriding CI_PROJECT_DIR ?

because, i don't think it does what you think it does in gitlab.com

image

PS:
https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/ci/variables/predefined_variables.md?plain=1#L15-16

if not #1330 is probably what you're requesting for

@BenediktBertsch
Copy link
Author

what exactly are you trying to achieve here by overriding CI_PROJECT_DIR ?

We got a template that is essentially looking like that:

  - /kaniko/executor --context ${DOCKER_CONTEXT:-$CI_PROJECT_DIR} ${DOCKER_MIRRORS} ${DOCKER_BUILD_ARGS} --dockerfile "${DOCKERFILE:-$CI_PROJECT_DIR/Dockerfile}" --no-push

So we were until now just adapting the CI_PROJECT_DIR to e.g. our docker folder like CI_PROJECT_DIR: "docker", instead we could also just define beforehand the full path of DOCKERFILE. In our testing with gitlab-ci-local we saw that the behavior differs. The source of that is that as far as I read the code the CI_PROJECT_DIR gets always overwritten with some default value.

I think its a bug because the behavior differs between gitlab-ci-local and the real pipeline but its up to you guys to decide on that. I do know that we can easily resolve it on our side but my expection would've been that the prio is more like this: gitlab-ci.yml, .env, global .env and then if some default values are not set set them.

@ANGkeith
Copy link
Collaborator

oo if that's the case why not use other variable name instead of overriding the pre-defined variables ?

since it's explicitly recommended against from doing so

@BenediktBertsch
Copy link
Author

oo if that's the case why not use other variable name instead of overriding the pre-defined variables ?

since it's explicitly recommended against from doing so

Yeah already did it, just wanted to confirm if this behavior is intended. I mean gitlab says its not recommended is enough for me to close this issue.

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