Commit e2763552 authored by Stan Hu's avatar Stan Hu

Fix path separator for CI_PROJECT_DIR in Windows

Internally, the runner uses paths with the `/` separator, but
since CI_PROJECT_DIR is an externally-facing path that can be used in
scripts, we need to ensure that it has the right separator.

Closes #2841
parent 5e6f0580
Pipeline #41721768 passed with stages
in 27 minutes and 53 seconds
v11.7.0 (2019-01-22)
- Fix path separator for CI_PROJECT_DIR in Windows !1128
v11.6.0 (2018-12-22)
- Make compatibility chart super clear and remove old entries !1078
- Add slack notification option for 'dep status' check failures !1072
......
......@@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
......@@ -477,7 +478,7 @@ func (b *Build) String() string {
func (b *Build) GetDefaultVariables() JobVariables {
return JobVariables{
{Key: "CI_PROJECT_DIR", Value: b.FullProjectDir(), Public: true, Internal: true, File: false},
{Key: "CI_PROJECT_DIR", Value: filepath.FromSlash(b.FullProjectDir()), Public: true, Internal: true, File: false},
{Key: "CI_SERVER", Value: "yes", Public: true, Internal: true, File: false},
}
}
......
......@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"testing"
"time"
......@@ -629,6 +630,21 @@ func TestDebugTrace(t *testing.T) {
assert.True(t, build.IsDebugTraceEnabled(), "IsDebugTraceEnabled should be true if CI_DEBUG_TRACE is set to true")
}
func TestDefaultEnvVariables(t *testing.T) {
assert := assert.New(t)
buildDir := "/tmp/test-build/dir"
build := Build{
BuildDir: buildDir,
}
vars := build.GetAllVariables().StringList()
assert.NotNil(vars)
assert.Contains(vars, "CI_PROJECT_DIR="+filepath.FromSlash(buildDir))
assert.Contains(vars, "CI_SERVER=yes")
}
func TestSharedEnvVariables(t *testing.T) {
for _, shared := range [...]bool{true, false} {
t.Run(fmt.Sprintf("Value:%v", shared), func(t *testing.T) {
......
......@@ -86,7 +86,7 @@ SET CI_COMMIT_REF_NAME=master
SET CI_JOB_ID=1
SET CI_REPOSITORY_URL=http://gitlab.example.com/group/project.git
SET CI_PROJECT_ID=1
SET CI_PROJECT_DIR=Z:/Gitlab/tests/test/builds/0/project-1
SET CI_PROJECT_DIR=Z:\Gitlab\tests\test\builds\0\project-1
SET CI_SERVER=yes
SET CI_SERVER_NAME=GitLab CI
SET CI_SERVER_VERSION=
......@@ -100,7 +100,7 @@ echo multiline!nl!tls!nl!chain > C:\GitLab-Runner\builds\0\project-1.tmp\CI_SERV
SET CI_SERVER_TLS_CA_FILE=C:\GitLab-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
echo Cloning repository...
rd /s /q "C:\GitLab-Runner\builds\0\project-1" 2>NUL 1>NUL
"git" "clone" "http://gitlab.example.com/group/project.git" "Z:/Gitlab/tests/test/builds/0/project-1"
"git" "clone" "http://gitlab.example.com/group/project.git" "Z:\Gitlab\tests\test\builds\0\project-1"
IF %errorlevel% NEQ 0 exit /b %errorlevel%
cd /D "C:\GitLab-Runner\builds\0\project-1"
......@@ -133,7 +133,7 @@ SET CI_COMMIT_REF_NAME=master
SET CI_JOB_ID=1
SET CI_REPOSITORY_URL=Z:\Gitlab\tests\test
SET CI_PROJECT_ID=1
SET CI_PROJECT_DIR=Z:/Gitlab/tests/test/builds/0/project-1
SET CI_PROJECT_DIR=Z:\Gitlab\tests\test\builds\0\project-1
SET CI_SERVER=yes
SET CI_SERVER_NAME=GitLab CI
SET CI_SERVER_VERSION=
......@@ -160,7 +160,7 @@ SET CI_COMMIT_REF_NAME=master
SET CI_JOB_ID=1
SET CI_REPOSITORY_URL=Z:\Gitlab\tests\test
SET CI_PROJECT_ID=1
SET CI_PROJECT_DIR=Z:/Gitlab/tests/test/builds/0/project-1
SET CI_PROJECT_DIR=Z:\Gitlab\tests\test\builds\0\project-1
SET CI_SERVER=yes
SET CI_SERVER_NAME=GitLab CI
SET CI_SERVER_VERSION=
......@@ -215,7 +215,7 @@ echo "Running on $env:computername..."
$env:CI_REPOSITORY_URL=$CI_REPOSITORY_URL
$CI_PROJECT_ID="1"
$env:CI_PROJECT_ID=$CI_PROJECT_ID
$CI_PROJECT_DIR="Z:/Gitlab/tests/test/builds/0/project-1"
$CI_PROJECT_DIR="Z:\Gitlab\tests\test\builds\0\project-1"
$env:CI_PROJECT_DIR=$CI_PROJECT_DIR
$CI_SERVER="yes"
$env:CI_SERVER=$CI_SERVER
......@@ -244,7 +244,7 @@ echo "Running on $env:computername..."
Remove-Item -Force -Recurse "C:\GitLab-Runner\builds\0\project-1"
}
& "git" "clone" "https://gitlab.com/group/project.git" "Z:/Gitlab/tests/test/builds/0/project-1"
& "git" "clone" "https://gitlab.com/group/project.git" "Z:\Gitlab\tests\test\builds\0\project-1"
if(!$?) { Exit $LASTEXITCODE }
cd "C:\GitLab-Runner\builds\0\project-1"
......@@ -285,7 +285,7 @@ if(!$?) { Exit $LASTEXITCODE }
$env:CI_REPOSITORY_URL=$CI_REPOSITORY_URL
$CI_PROJECT_ID="1"
$env:CI_PROJECT_ID=$CI_PROJECT_ID
$CI_PROJECT_DIR="Z:/Gitlab/tests/test/builds/0/project-1"
$CI_PROJECT_DIR="Z:\Gitlab\tests\test\builds\0\project-1"
$env:CI_PROJECT_DIR=$CI_PROJECT_DIR
$CI_SERVER="yes"
$env:CI_SERVER=$CI_SERVER
......@@ -330,7 +330,7 @@ if(!$?) { Exit $LASTEXITCODE }
$env:CI_REPOSITORY_URL=$CI_REPOSITORY_URL
$CI_PROJECT_ID="1"
$env:CI_PROJECT_ID=$CI_PROJECT_ID
$CI_PROJECT_DIR="Z:/Gitlab/tests/test/builds/0/project-1"
$CI_PROJECT_DIR="Z:\Gitlab\tests\test\builds\0\project-1"
$env:CI_PROJECT_DIR=$CI_PROJECT_DIR
$CI_SERVER="yes"
$env:CI_SERVER=$CI_SERVER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment