1

I am in the Debian9. And sudo su to become root user. After that I run the command gitlab-runner register. But for some reasons. I got the isolated environment not the same like when I login to the server over ssh

gitlab-runner --version
Version:      10.8.0
Git revision: 079aad9e
Git branch:
GO version:   go1.8.7
Built:        2018-05-22T03:24:56+00:00
OS/Arch:      linux/amd64

When I put env in the before_script I found the different environment. Then I put source ~/.bashrc to it. Also does not make any change. How to let shell runner use my normal login user environement?

Update:
When I execute env (by putting in before_script) I got this output

$ env
CI_RUNNER_EXECUTABLE_ARCH=linux/amd64
CI_COMMIT_TITLE=add config
CI_JOB_TOKEN=xxxxxxxxxxxxxxxxxxxx
CI_BUILD_REF_NAME=master
CI_REGISTRY_PASSWORD=xxxxxxxxxxxxxxxxxxxx
CI_RUNNER_TAGS=provider, oauth, mp
CI_SHARED_ENVIRONMENT=true
CI_JOB_NAME=test
CI_SERVER_VERSION=10.8.4
DJANGO_SETTINGS_MODULE=config.settings.local
LANG=en_US.UTF-8
GITLAB_CI=true
CI_SERVER_REVISION=2268d0c
CI_PROJECT_VISIBILITY=private
OLDPWD=/home/gitlab-runner
INVOCATION_ID=7dd516612949410c8ca8e4e59696f9fd
CI_COMMIT_SHA=9030892858b5ca92c7b36a81f573f187e6d14090
CI_COMMIT_MESSAGE=add config

CI_BUILD_STAGE=test
CI_PROJECT_URL=https://mbx-git.magicboxasia.com/sarit/mhu_ped_oauth_provider
CI_COMMIT_REF_SLUG=master
CI_SERVER_NAME=GitLab
CI_RUNNER_VERSION=10.8.0
CI_BUILD_NAME=test
CI=true
XDG_SESSION_ID=c5
CI_REGISTRY_USER=gitlab-ci-token
USER=gitlab-runner
CI_PROJECT_ID=96
CI_PIPELINE_ID=4399
CI_COMMIT_DESCRIPTION=
PWD=/home/gitlab-runner/builds/f304ea76/0/sarit/mhu_ped_oauth_provider
GITLAB_FEATURES=
HOME=/home/gitlab-runner
JOURNAL_STREAM=8:19161
CI_REGISTRY=docker-registry.magicboxasia.com
CI_BUILD_TOKEN=xxxxxxxxxxxxxxxxxxxx
CI_BUILD_ID=5514
CONFIG_FILE=/etc/gitlab-runner/config.toml
GITLAB_USER_NAME=Sarit Ritwirune
CI_PROJECT_PATH_SLUG=sarit-mhu-ped-oauth-provider
DATABASE_URL=postgres://postgres:postgres@postgres:5432/mp_oauth_provider
POSTGRES_DB=poinkdb
[email protected]
CI_COMMIT_REF_NAME=master
CI_REGISTRY_IMAGE=docker-registry.magicboxasia.com/sarit/mhu_ped_oauth_provider
CI_SERVER_TLS_CA_FILE=/home/gitlab-runner/builds/f304ea76/0/sarit/mhu_ped_oauth_provider.tmp/CI_SERVER_TLS_CA_FILE
CI_RUNNER_ID=42
CI_SERVER=yes
CI_JOB_ID=5514
CI_REPOSITORY_URL=https://gitlab-ci-token:[email protected]/sarit/mhu_ped_oauth_provider.git
MAIL=/var/mail/gitlab-runner
SHELL=/bin/bash
GITLAB_USER_LOGIN=sarit
CI_RUNNER_REVISION=079aad9e
CI_CONFIG_PATH=.gitlab-ci.yml
CI_PROJECT_NAME=mhu_ped_oauth_provider
POSTGRES_PASSWORD=postgres
POSTGRES_USER=postgres
SHLVL=2
CI_RUNNER_DESCRIPTION=MP OAuth Provider
CI_PROJECT_PATH=sarit/mhu_ped_oauth_provider
LOGNAME=gitlab-runner
XDG_RUNTIME_DIR=/run/user/999
GITLAB_USER_ID=39
CI_BUILD_BEFORE_SHA=e36e718d09f89095972ddf60ebf1fc1931282ae4
CI_BUILD_REF=9030892858b5ca92c7b36a81f573f187e6d14090
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
CI_PIPELINE_SOURCE=push
CI_PROJECT_NAMESPACE=sarit
CI_PROJECT_DIR=/home/gitlab-runner/builds/f304ea76/0/sarit/mhu_ped_oauth_provider
CI_JOB_STAGE=test
CI_BUILD_REF_SLUG=master
_=/usr/bin/env
$ python -V
Python 2.7.13
4
  • How have you set up the gitlab-runner? If you've set the runner up using sudo, it would have created a separate gitlab-runner account and hence would use a different user environment. Commented Jun 18, 2018 at 10:18
  • I have separate gitlab-runner. But the problem is not there. The problem is when I let it run python, pip, pyenv, ... it returns command not found. Commented Jun 18, 2018 at 11:03
  • Is python, pip, pyenv installed globally? Have you tried becoming the gitlab-runner and accessing the commands there? Commented Jun 18, 2018 at 12:08
  • @Rekovni Sure. I have set it already. This is just happen with 10.8.0 by previous project 10.7.0 does not has this problem. In worst case I will use docker runner instead of shell runner Commented Jun 18, 2018 at 14:25

2 Answers 2

1

I am not sure this is the best practice or not, but I directly set the PATH by this in order to let the gitlab-runner use same as I do when ssh remote to server. But at least it works.

variables:
    PATH: "/home/gitlab-runner/.pyenv/plugins/pyenv-virtualenv/shims:/home/gitlab-runner/.pyenv/shims:/home/gitlab-runner/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
Sign up to request clarification or add additional context in comments.

Comments

1

Similar to setting variables directly in gitlab-ci ...

job: 
  variables:
    MY_CUSTOM_VARIABLE:my_variable

Better place an environment file in your project's main directory within e.g a file .ci/env. In project directory (same level as .gitlab-ci.yml):

$ mkdir .ci
$ vi .ci/env

Then, in .gitlab-ci.yml copy the file into build context:

before_script:
  - . .ci/env

In there you can place your custom or modified variables as in:

Any custom variables

export MY_CUSTOM_VARIABLE=my_variable

Pyenv and pipenv context variables:

export PYENV_ROOT="$HOME/.pyenv"
export PATH=/home/gitlab-runner/.pyenv/shims:/home/gitlab-runner/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export PIPENV_PYTHON="$PYENV_ROOT/shims/python"

1 Comment

Thank you for your answer. I will try your answer next time with new project.

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.