Skip to content

Cannot build with UNC working directory

Summary

I tried to run a pipeline with a Windows runner using a UNC path (\\host\foo\bar\GitLab-Runner) as its working directory. This failed to execute successfully with the Powershell executor.

Steps to reproduce

  1. Install Gitlab runner as a service on Windows, configured to use the shell executor with Powershell, and with a "path to executable" similar to:
C:\GitLab-Runner\gitlab-runner.exe run --working-directory \\host\foo\bar\GitLab-Runner --config \\host\foo\bar\GitLab-Runner\config.toml --service gitlab-runner --syslog
  1. Add the runner as a specific runner for the project.

  2. Trigger a build to run on the runner.

Actual behavior

Build fails with errors related to path concatenation (see logs below).

From some investigation, I think the underlying cause is the use of path.join in shells/powershell.go. What I think (but did not debug extensively, as I don't really know go) is happening is this:

  1. \\host\foo\bar\GitLab-Runner is converted to //host/foo/bar/GitLab-Runner

  2. In TmpFile, path.join("//host/foo/bar/Gitlab-Runner", "builds/project.tmp/FILENAME") collapses sequential slashes and produces /host/foo/bar/GitLab-Runner/builds/project.tmp/FILENAME.

  3. /host/foo/.../project.tmp/FILENAME is converted to \host\foo\...\project.tmp\FILENAME, which is no longer a UNC path.

  4. In Absolute, the path \host\foo\...\project.tmp\FILENAME does not pass the IsAbs test and is therefore concatenated to the end of CWD.

I have tested changing path.join to filepath.join in shells/powershell.go, which solved my particular issue. I will create a merge request for this.

Expected behavior

A successful (or at least attempted) build.

Relevant logs and/or screenshots

Running with gitlab-runner 11.4.2 (cf91d5e1)
  on some-host 12345678
Using Shell executor...
Running on SOME-HOST...
Set-Content : Could not find a part of the path '\\host\foo\bar\GitLab-Runner\hos
t\foo\bar\GitLab-Runner\builds\12345678\0\groupname\project.tmp\CI_SERVER_TLS_CA_FI
LE'.
At C:\Users\user_name\AppData\Local\Temp\build_script87654321\script.ps1:9 char:1
+ Set-Content "$CurrentDirectory\host\foo\bar\GitLab-Runner ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\host\foo\bar...VER_TLS_CA_FILE:String) [Set-Cont 
   ent], DirectoryNotFoundException
    + FullyQualifiedErrorId : GetContentWriterDirectoryNotFoundError,Microsoft.PowerShell.Commands 
   .SetContentCommand
 
error: could not lock config file \host\foo\bar\GitLab-Runner\builds\12345678\0\groupname\project.tmp\git-template/config: No such file or directory
cd : Cannot find path '\\host\foo\bar\GitLab-Runner\builds\12345678\0\groupname\p
roject' because it does not exist.
At C:\Users\user_name\AppData\Local\Temp\build_script391920169\script.ps1:122 char:1
+ cd "\\host\foo\bar\GitLab-Runner\builds\12345678\0\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\host\foo\bar...groupname\project:String) [Set-Loca 
   tion], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
 
ERROR: Job failed: exit status 1

Environment description

Custom GitLab installation, GitLab Runner with Powershell executor.

Used GitLab Runner version

Running with gitlab-runner 11.4.2 (cf91d5e1)
  on some-host 12345678
Using Shell executor...

Possible fixes

A Community contribution had a fix ready !1083 (closed) just some missing test cases

Edited by Steve Xuereb