1

I'm running the following in a Docker container (in a Gitlab CI/CD pipeline) with the python:3 image. I installed git using the following command:

apt-get update
apt-get install -y git

Based on the output, this wasn't even necessary because git was already installed. Unfortunately, I got the following output that states that the "git" command was not found even though the "git" command was used earlier in the script. Does anyone have any idea what's going on here?

$ apt-get update
Get:1 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:2 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [109 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2592 B]
Fetched 8494 kB in 1s (6639 kB/s)
Reading package lists...
$ apt-get install -y git
Reading package lists...
Building dependency tree...
Reading state information...
git is already the newest version (1:2.30.2-1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
$ git --version
git version 2.30.2
$ git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"
$ git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}"
$ regex="^report\/[^\/]*\/([^\/]*)\/(.*)"
$ [[ $CI_COMMIT_BRANCH =~ $regex ]]
$ CUSTOMER="${BASH_REMATCH[1]}"
$ PATH="${BASH_REMATCH[2]}"
$ RELPATH=$(.ci/scripts/find_relative.py "${CI_PROJECT_PATH}" "${PATH}")
$ git submodule add ${RELPATH} ${CUSTOMER}
/scripts-530-146123/step_script: line 151: git: command not found
ERROR: Job failed: command terminated with exit code 1

1 Answer 1

1

In this line:

PATH="${BASH_REMATCH[2]}"

you alter the PATH variable. I suspect it no longer has /usr/bin (or wherever git is) in the new path.

Sign up to request clarification or add additional context in comments.

4 Comments

Oh wow I feel dumb. I can't believe I tried to use PATH as a generic variable haha. Thanks!
@MichaelaDeForest no worries :) Feel free to Accept my answer if that's fixed the problem.
I will! just waiting for SO to allow me to accept an answer. You answered too quickly :)
@MichaelaDeForest: it happens (using a "reserved name" as it were). In fact it's really common in a lot of programming, so much so that there are linters that warn you if you "shadow" some name by mistake. A lot of the time it works fine when you do it, and then bites you later when you add more stuff to something...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.