Why I got an error in my gitlab CI with Pip which is not found?

Viewed 7896

I'm trying to use gitlab CI for the first time. I just want to test (not to deploy) a Python program on it. I don't know why but it failed on pip, which is not found...

Here is the error message of gitlab :

Skipping Git submodules setup
$ pip install -r requirements.txt
/bin/bash: line 71: pip: command not found
ERROR: Job failed: exit code 1

And here my .gitlab-ci.yaml:

stages:
  - build
  - test

myJob:
  stage: build
  image: python:3.6
  script:
    - apt-get update -q -y
    - apt-get install -y python-pip
    - python -V
    - echo "hello world"
    - pip install -r requirements.txt

myJob2:
  stage: test
  script:
    - python test.py

Neither the hello world nor the Python version is printed. So I probably made a basic mistake, but which one?

1 Answers

Different jobs in your pipeline are run in different containers. To be precise, they run in the container that you specify as image. The job myJob runs inside a python:3.6 container, so you have the pip command and everything works fine.

For your second job (myJob2), you did not specify any image, so the default image will be used, which will likely not be a python image.

Even if your second job was running inside a python container, it would still fail because of missing dependencies. You are installing the dependencies in the first job, but you did not specify any artifacts that should be passed to the next job. For more information on passing these artifacts check the Gitlab CI reference.

The following .gitlab-ci.yml should work:

stages:
  - build
  - test

myJob:
  stage: build
  image: python:3.6
  script:
    - apt-get update -q -y
    - apt-get install -y python-pip
    - python -V
    - echo "hello world"
    - pip install -r requirements.txt
  artifacts:
    untracked: true

myJob2:
  stage: test
  image: python:3.6
  script:
    - python test.py
Related