Gitlab-runner as non-root does not clone repo

I found the problem! Nasty, bordering on evil, I’d say. So here goes:

  • The shell executor runs “bash --login”. Quite why it needs a login shell, I don’t know. Anyway…

  • The first such shell command it runs is in the Prepare stage, which looks pretty innocuous

    echo “Running on $(hostname)…”

  • That surely doesn’t fail, does it? Not in itself - but being a login shell, bash then executes a .bash_logout if it exists. Mine looked like this:

    pkill -f something_irrelevant
    true

  • The pkill doesn’t find any matching processes, so exits with status 1.

  • Because the generated script does “set -e” at the top, this causes bash to exit with non-zero status.

  • Although the Prepare stage failed, gitlab-runner seemingly carried on to attempt the GetSources stage, but did not add any commands to the script which would fetch the sources. I looked at the latest source code for gitlab-runner; although I’m not familiar with go, I don’t see how it can do that. Maybe the released binary was built from a significantly different source version.

So my workaround was to comment out the pkill in my .bash_logout (it was historical cruft anyway). Putting “set +e” at the top of .bash_logout also works.

4 Likes