custom executor does not use git templates during get_sources
Summary
During the get_sources
step of the custom
executor, the git init
command in the script is such that git does not use the prescribed templates. The following warning is issued (visible in the CI job log):
warning: templates not found in path\to\my\project.tmp\git-template
Steps to reproduce
Use the custom executor and examine the script passed in during the get_sources
. There is a line (line 94 for me) that does the initialization.
Actual behavior
Initialization appears as:
"git" "init" "builds/0/long-path/random/0/path/project_name" "--template" "builds/0/long-path/random/0/path/project_name.tmp/git-template"
The paths passed to git init
and the --template
switch are both relative to CWD.
Expected behavior
git
expects the --template
switch to be relative to the new repo. In my custom executor, I look for a line that matches the above and replace it using:
def _replaceGitInitReplacer(match):
fmt = '"git" "init" "{0}/{1}" "--template" "../{1}.tmp/git-template"'
return fmt.format(*match.groups())
def _replaceGitInit(script):
regex = '^.?git.?\s+.?init.?\s+.?(.*?)[\\\/]([^\\\/"\']*).?\s+.?--template.*'
regex = re.compile(regex, re.MULTILINE)
return regex.sub(_replaceGitInitReplacer, script)
script = _replaceGitInit(script)
such that what was:
"git" "init" "builds/0/long-path/random/0/path/project_name" "--template" "builds/0/long-path/random/0/path/project_name.tmp/git-template"
is now:
"git" "init" "builds/0/long-path/random/0/path/project_name" "--template" "../project_name.tmp/git-template"
Relevant logs and/or screenshots
job log
Fetching changes...
Initialized empty Git repository in d:/path/removed/for/security/project_name/.git/
Created fresh repository.
warning: templates not found in path\removed\for\security\project_name.tmp\git-template
Checking out d1d57ff5 as custom_executor...
Skipping Git submodules setup
Environment description
config.toml contents
concurrent = 5
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Windows"
url = "our-ce-url"
token = "myrunnertoken"
executor = "custom"
shell = "cmd"
[runners.custom]
config_exec = "/path/to/myscript.sh"
prepare_exec = "/path/to/myscript.sh"
run_exec = "/path/to/myscript.sh"
cleanup_exec = "/path/to/myscript.sh"
Yes, running an executor on a Linux machine to launch Windows jobs.
Used GitLab Runner version
Version: 12.1.0
Git revision: de7731dd
Git branch: 12-1-stable
GO version: go1.8.7
Built: 2019-07-19T13:53:04+0000
OS/Arch: linux/amd64
Possible fixes
Line abstract.go:308 could stick in the absolute path:
w.Command("git", "init", projectDir, "--template", path.Abs(templateDir))