3

I want to run my Jupyter notebooks with my pipeline. To do this i need runipy. And to install runipy on the gitlab runner i need python. But when i want to run the .gitlab-ci.yml script it gets stuck at printing the python version because python is not recognized.

.gitlab-ci.yml:

image: python:3.9

before_script:
  - python -V
  - pip install runipy

error:

Running with gitlab-runner 13.3.1 (738bbe5a)
  on JavaUnitTestRunner vr_SgzNd
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on DESKTOP-DJVC49J...
Getting source from Git repository
00:03
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/Gitlab-Runner/builds/vr_SgzNd/0/I438220/pharma/.git/
Checking out 65a225c0 as pipeline...
git-lfs/2.9.2 (GitHub; windows amd64; go 1.12.7; git 0274d856)
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ python -V
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
 the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\WINDOWS\TEMP\build_script377697220\script.ps1:195 char:1
+ python -V
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
ERROR: Job failed: exit status 1

When i try the same command in cmd everything works just fine.

4
  • Hey, just following up. Did you solve your problem? Commented Apr 6, 2021 at 3:16
  • Not yet, i looked at the answer you gave me, but i could not figure out what i had to put after pre_build_script. I tried to change the path to the location where python is installed. But that didn't help either. Also i tried to add the path to the path variables in the control panel, But also no success. Then i tried to add the path in the gitlab-ci file itself. And that resulted in this error: The term 'git' is not recognized. Commented Apr 6, 2021 at 8:09
  • 1
    Aha! adding environment = ['PATH=%PATH%;C:/Program Files/Git/bin;C:\Users\{user}\AppData\Local\Programs\Python\Python39;C:\Users\{user}\AppData\Local\Programs\Python\Python39\Scripts'] to the config.toml file did the trick. Thank you so much for the help. :) Commented Apr 6, 2021 at 12:34
  • Awesome!! Glad it worked! Commented Apr 6, 2021 at 12:36

3 Answers 3

7

Based on your log, you're using the shell executor. This will run commands on your local shell, just like you would yourself. The problem is the runner does not use your OS environment variables, so you need to add your python, git, etc. paths to the runner's path environment variable.

The best way to do this is to configure the path variables explicitly in the environment variable in the [[runners]] section of your runner's config.toml. The config.toml file can either be in /etc/gitlab-runner/, ~/.gitlab-runner or / root. This StackOverflow thread shows how to do this. Please read Advanced Configurations for more info.

If you want to download and use a custom docker image, like python:3.9, you need to use the Docker Executor.

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

Comments

3

If you are using Windows Server, make sure that the environment variables are defined in the system section, Python sets these items in the user section by default.

1 Comment

I found you have to restart the host machine in order to have new System EnVars be seen by the GitLab Runner. Maybe restarting the Runner service will have the desired effect as well
0

I installed python and tried everything except restarting the Windows Server itself. When I restarted the path variable worked. Didn't needed to update the config.toml too.

Also as Francois B said, restarting the gitlab-runner service works without restarting the whole servrer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.