Writing CI_SERVER_TLS_CA_FILE with custom executor
Summary
The generated powershell script for a custom executor has problems writing the CI_SERVER_TLS_CA_FILE file.
Steps to reproduce
I'm writing a custom gitlab executor that runs on Linux, but executes the CI jobs on a remote Windows machine. I am using the Powershell shell.
During the "config" stage of the custom executor, I am generating the following configuration object:
{
"builds_dir": "u:\\users\\lxd\\gitlab\\builds\\0\\lxd-gitlab-custom-executor",
"builds_dir_is_shared": true,
"cache_dir": "u:\\users\\lxd\\gitlab\\cache\\0\\lxd-gitlab-custom-executor",
"driver": {
"name": "gitlab_custom_runner",
"version": "0.1.2"
}
}
Both the builds_dir
and cache_dir
are valid paths on the remote Windows machine.
During the "get_sources" stage of the custom executor, the generated PS script fails with an error. Here's the error:
Set-Content : Could not open the alternate data stream '\users\lxd\gitlab\build
s\0\lxd-gitlab-custom-executor\9Gd61quw\0\lxd\gitlab-custom-executor.tmp\CI_SER
VER_TLS_CA_FILE' of the file 'C:\LSF_10.1\tmp\u'.
At D:\temp\restore_cache.ps1:21 char:1
+ Set-Content "$CurrentDirectory\u:\users\lxd\gitlab\builds\0\lxd-gitla ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\LSF_10.1\tmp\u:String) [Set-
Content], FileNotFoundException
+ FullyQualifiedErrorId : GetContentWriterFileNotFoundError,Microsoft.Powe
rShell.Commands.SetContentCommand
And I think the problem is because of how the PS script is generated:
$CurrentDirectory = (Resolve-Path .\).Path
New-Item -ItemType directory -Force -Path "u:\users\lxd\gitlab\builds\0\lxd-gitlab-custom-executor\9Gd61quw\0\lxd\gitlab-custom-executor.tmp" | out-null
Set-Content "$CurrentDirectory\u:\users\lxd\gitlab\builds\0\lxd-gitlab-custom-executor\9Gd61quw\0\lxd\gitlab-custom-executor.tmp\CI_SERVER_TLS_CA_FILE" -Value "contents of file have been elided when filing this gitlab issue" -Encoding UTF8 -Force
$CI_SERVER_TLS_CA_FILE="$CurrentDirectory\u:\users\lxd\gitlab\builds\0\lxd-gitlab-custom-executor\9Gd61quw\0\lxd\gitlab-custom-executor.tmp\CI_SERVER_TLS_CA_FILE"
$env:CI_SERVER_TLS_CA_FILE=$CI_SERVER_TLS_CA_FILE
In particular, the $CurrentDirectory
stuff looks suspicious. The file path is already absolute, but gitlab seems to think the path is relative.
I should note that the gitlab runner process that is generating these powershell scripts is running on Linux. But the powershell scripts are being copied to a windows machine for execution. So I think this code in powershell.go
is getting confused:
func (b *PsWriter) Absolute(dir string) string {
if filepath.IsAbs(dir) {
return dir
}
b.Line("$CurrentDirectory = (Resolve-Path .\\).Path")
return filepath.Join("$CurrentDirectory", dir)
}
Since this is run on Linux, I bet that filepath.IsAbs(dir)
is returning false.
Used GitLab Runner version
Version: 12.8.0
Git revision: 1b659122
Git branch: 12-8-stable
GO version: go1.13.7
Built: 2020-02-22T03:36:44+0000
OS/Arch: linux/amd64
Possible fixes
I think that if I use a relative path for "builds_dir" and "cache_dir", then things will work out (though this makes it harder to control the working directories).