Search code examples
shellgitlabgitlab-cigitlab-ci-runner

gitlab-runner shell isn't using configuration from config.toml


System: WSL2 instance of Ubuntu 18.04

I am locally testing out small gitlab-ci jobs using gitlab-runner exec shell <job> but the default behavior of checking the source files into <working-directory>/builds/<short-token>/<concurrent-id>/<namespace>/<project-name> is causing problems where my IDE stops recognizing the parent git repo as valid, which is annoying.

My solution is to move the default location of the build and cache files outside of the working directory. I followed the documentation to modify the config.toml, which was initially empty, to add these definitions:

[[runners]]
  name = "shell executor runner"
  executor = "shell"
  shell = "sh"
  builds_dir = "/home/myuser/dev/gitlab-runner-files/builds"
  cache_dir = "/home/myuser/dev/gitlab-runner-files/cache"

However, when I try again to run gitlab-runner exec shell my-job it's showing this initial output, indicating it's not using the runner that I configured and so it's also not using my directory overrides.

Runtime platform                                    arch=amd64 os=linux pid=26105 revision=dcfb4b66 version=15.10.1
WARNING: You most probably have uncommitted changes.
WARNING: These changes will not be tested.
Running with gitlab-runner 15.10.1 (dcfb4b66)
Preparing the "shell" executor
Using Shell (bash) executor...
executor not supported                              job=1 project=0 referee=metrics
Preparing environment
Running on PC-01099...
Getting source from Git repository
Fetching changes...
Initialized empty Git repository in /home/myuser/dev/my-app/builds/0/project-0/.git/

How do I get it to use the runner that I configured in config.toml instead of whatever it's defaulting to here?


Solution

  • The command gitlab-runner exec shell my-job fires the job with the shell executor. It does not load the advanced configuration file config.toml. Commands that support the advanced configuration have an option -c, --config and/or support the CONFIG_FILE environment parameter.

    Nevertheless you can use the exec command and try out what you wanted to do with the config.toml configuration, just provide the according options and environment parameters to the runner exec shell command, compare:

    $ gitlab-runner exec shell --help | grep dir
       --builds-dir value           Directory where builds are stored [$RUNNER_BUILDS_DIR]
       --cache-dir value            Directory where build cache is stored [$RUNNER_CACHE_DIR]
       --custom_build_dir-enabled   Enable job specific build directories [$CUSTOM_BUILD_DIR_ENABLED]
       --docker-cache-dir value     Directory where to store caches [$DOCKER_CACHE_DIR]
    

    (use a pager, the output is pretty wide and tall)

    $ gitlab-runner exec shell --builds-dir /tmp/runner-builds my-job
    ... 
    

    Once you've got your configuration switch to environment parameter (a.k.a. variables):

    $ RUNNER_BUILDS_DIR=/tmp/runner-builds gitlab-runner exec shell my-job
    ...
    

    Then configure your runner task in your Integrated Development Environment (IDE) providing the environment of your choice.