Skip to content
Snippets Groups Projects
Commit 0ddb8d48 authored by Tomasz Maczukin's avatar Tomasz Maczukin :speech_balloon:
Browse files

Merge branch 'zj-cleanup-variables' into 'master'

Cleanup variables set on GitLab already

Closes #2253

See merge request !523
parents 1ef60e3c 85c8ee2b
No related branches found
No related tags found
Loading
Pipeline #
......@@ -363,21 +363,8 @@ func (b *Build) String() string {
func (b *Build) GetDefaultVariables() JobVariables {
return JobVariables{
{"CI", "true", true, true, false},
{"CI_DEBUG_TRACE", "false", true, true, false},
{"CI_BUILD_REF", b.GitInfo.Sha, true, true, false},
{"CI_BUILD_BEFORE_SHA", b.GitInfo.BeforeSha, true, true, false},
{"CI_BUILD_REF_NAME", b.GitInfo.Ref, true, true, false},
{"CI_BUILD_ID", strconv.Itoa(b.ID), true, true, false},
{"CI_BUILD_REPO", b.GitInfo.RepoURL, true, true, false},
{"CI_BUILD_TOKEN", b.Token, true, true, false},
{"CI_PROJECT_ID", strconv.Itoa(b.JobInfo.ProjectID), true, true, false},
{"CI_PROJECT_DIR", b.FullProjectDir(), true, true, false},
{"CI_SERVER", "yes", true, true, false},
{"CI_SERVER_NAME", "GitLab CI", true, true, false},
{"CI_SERVER_VERSION", "", true, true, false},
{"CI_SERVER_REVISION", "", true, true, false},
{"GITLAB_CI", "true", true, true, false},
{Key: "CI_PROJECT_DIR", Value: b.FullProjectDir(), Public: true, Internal: true, File: false},
{Key: "CI_SERVER", Value: "yes", Public: true, Internal: true, File: false},
}
}
......
......@@ -378,3 +378,26 @@ func TestRunSuccessOnSecondAttempt(t *testing.T) {
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.NoError(t, err)
}
func TestDebugTrace(t *testing.T) {
build := &Build{}
assert.False(t, build.IsDebugTraceEnabled(), "IsDebugTraceEnabled should be false if CI_DEBUG_TRACE is not set")
successfulBuild, err := GetSuccessfulBuild()
assert.NoError(t, err)
successfulBuild.Variables = append(successfulBuild.Variables, JobVariable{"CI_DEBUG_TRACE", "false", true, true, false})
build = &Build{
JobResponse: successfulBuild,
}
assert.False(t, build.IsDebugTraceEnabled(), "IsDebugTraceEnabled should be false if CI_DEBUG_TRACE is set to false")
successfulBuild, err = GetSuccessfulBuild()
assert.NoError(t, err)
successfulBuild.Variables = append(successfulBuild.Variables, JobVariable{"CI_DEBUG_TRACE", "true", true, true, false})
build = &Build{
JobResponse: successfulBuild,
}
assert.True(t, build.IsDebugTraceEnabled(), "IsDebugTraceEnabled should be true if CI_DEBUG_TRACE is set to true")
}
......@@ -224,8 +224,8 @@ type UpdateJobRequest struct {
}
type JobCredentials struct {
ID int `long:"id" env:"CI_BUILD_ID" description:"The build ID to upload artifacts for"`
Token string `long:"token" env:"CI_BUILD_TOKEN" required:"true" description:"Build token"`
ID int `long:"id" env:"CI_JOB_ID" description:"The build ID to upload artifacts for"`
Token string `long:"token" env:"CI_JOB_TOKEN" required:"true" description:"Build token"`
URL string `long:"url" env:"CI_SERVER_URL" required:"true" description:"GitLab CI URL"`
TLSCAFile string `long:"tls-ca-file" env:"CI_SERVER_TLS_CA_FILE" description:"File containing the certificates to verify the peer when using HTTPS"`
}
......
......@@ -84,7 +84,7 @@ and straight forward access between container during the CI stages.
``` yaml
variables:
KUBERNETES_NAMESPACE_OVERWRITE: ci-${CI_BUILD_REF_NAME}
KUBERNETES_NAMESPACE_OVERWRITE: ci-${CI_COMMIT_REF_NAME}
```
Furthermore, to ensure only designated namespaces will be used during CI runs, inform the configuration
......
......@@ -80,11 +80,11 @@ IF %errorlevel% NEQ 0 exit /b %errorlevel%
goto :EOF
:prescript
SET CI=true
SET CI_BUILD_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
SET CI_BUILD_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
SET CI_BUILD_REF_NAME=master
SET CI_BUILD_ID=1
SET CI_BUILD_REPO=http://gitlab.example.com/group/project.git
SET CI_COMMIT_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
SET CI_COMMIT_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
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_SERVER=yes
......@@ -127,11 +127,11 @@ goto :EOF
:buildscript
SET CI=true
SET CI_BUILD_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
SET CI_BUILD_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
SET CI_BUILD_REF_NAME=master
SET CI_BUILD_ID=1
SET CI_BUILD_REPO=Z:\Gitlab\tests\test
SET CI_COMMIT_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
SET CI_COMMIT_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
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_SERVER=yes
......@@ -154,11 +154,11 @@ goto :EOF
:postscript
SET CI=true
SET CI_BUILD_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
SET CI_BUILD_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
SET CI_BUILD_REF_NAME=master
SET CI_BUILD_ID=1
SET CI_BUILD_REPO=Z:\Gitlab\tests\test
SET CI_COMMIT_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
SET CI_COMMIT_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
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_SERVER=yes
......@@ -203,16 +203,16 @@ echo "Running on $env:computername..."
& {
$CI="true"
$env:CI=$CI
$CI_BUILD_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
$env:CI_BUILD_REF=$CI_BUILD_REF
$CI_BUILD_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
$env:CI_BUILD_BEFORE_SHA=$CI_BUILD_BEFORE_SHA
$CI_BUILD_REF_NAME="master"
$env:CI_BUILD_REF_NAME=$CI_BUILD_REF_NAME
$CI_BUILD_ID="1"
$env:CI_BUILD_ID=$CI_BUILD_ID
$CI_BUILD_REPO="Z:\Gitlab\tests\test"
$env:CI_BUILD_REPO=$CI_BUILD_REPO
$CI_COMMIT_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
$env:CI_COMMIT_REF=$CI_COMMIT_REF
$CI_COMMIT_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
$env:CI_COMMIT_BEFORE_SHA=$CI_COMMIT_BEFORE_SHA
$CI_COMMIT_REF_NAME="master"
$env:CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
$CI_JOB_ID="1"
$env:CI_JOB_ID=$CI_JOB_ID
$CI_REPOSITORY_URL="Z:\Gitlab\tests\test"
$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"
......@@ -273,16 +273,16 @@ if(!$?) { Exit $LASTEXITCODE }
& {
$CI="true"
$env:CI=$CI
$CI_BUILD_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
$env:CI_BUILD_REF=$CI_BUILD_REF
$CI_BUILD_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
$env:CI_BUILD_BEFORE_SHA=$CI_BUILD_BEFORE_SHA
$CI_BUILD_REF_NAME="master"
$env:CI_BUILD_REF_NAME=$CI_BUILD_REF_NAME
$CI_BUILD_ID="1"
$env:CI_BUILD_ID=$CI_BUILD_ID
$CI_BUILD_REPO="Z:\Gitlab\tests\test"
$env:CI_BUILD_REPO=$CI_BUILD_REPO
$CI_COMMIT_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
$env:CI_COMMIT_REF=$CI_COMMIT_REF
$CI_COMMIT_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
$env:CI_COMMIT_BEFORE_SHA=$CI_COMMIT_BEFORE_SHA
$CI_COMMIT_REF_NAME="master"
$env:CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
$CI_JOB_ID="1"
$env:CI_JOB_ID=$CI_JOB_ID
$CI_REPOSITORY_URL="Z:\Gitlab\tests\test"
$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"
......@@ -318,16 +318,16 @@ if(!$?) { Exit $LASTEXITCODE }
& {
$CI="true"
$env:CI=$CI
$CI_BUILD_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
$env:CI_BUILD_REF=$CI_BUILD_REF
$CI_BUILD_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
$env:CI_BUILD_BEFORE_SHA=$CI_BUILD_BEFORE_SHA
$CI_BUILD_REF_NAME="master"
$env:CI_BUILD_REF_NAME=$CI_BUILD_REF_NAME
$CI_BUILD_ID="1"
$env:CI_BUILD_ID=$CI_BUILD_ID
$CI_BUILD_REPO="Z:\Gitlab\tests\test"
$env:CI_BUILD_REPO=$CI_BUILD_REPO
$CI_COMMIT_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
$env:CI_COMMIT_REF=$CI_COMMIT_REF
$CI_COMMIT_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
$env:CI_COMMIT_BEFORE_SHA=$CI_COMMIT_BEFORE_SHA
$CI_COMMIT_REF_NAME="master"
$env:CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
$CI_JOB_ID="1"
$env:CI_JOB_ID=$CI_JOB_ID
$CI_REPOSITORY_URL="Z:\Gitlab\tests\test"
$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"
......
......@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"strconv"
"strings"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
......@@ -144,6 +145,26 @@ func (c *GitLabCiYamlParser) prepareSteps(job *common.JobResponse) (err error) {
return
}
func (c *GitLabCiYamlParser) buildDefaultVariables(job *common.JobResponse) (defaultVariables common.JobVariables, err error) {
defaultVariables = common.JobVariables{
{"CI", "true", true, true, false},
{"GITLAB_CI", "true", true, true, false},
{"CI_SERVER_NAME", "GitLab CI", true, true, false},
{"CI_SERVER_VERSION", "", true, true, false},
{"CI_SERVER_REVISION", "", true, true, false},
{"CI_PROJECT_ID", strconv.Itoa(job.JobInfo.ProjectID), true, true, false},
{"CI_JOB_ID", strconv.Itoa(job.ID), true, true, false},
{"CI_JOB_NAME", job.JobInfo.Name, true, true, false},
{"CI_JOB_STAGE", job.JobInfo.Stage, true, true, false},
{"CI_JOB_TOKEN", job.Token, true, true, false},
{"CI_REPOSITORY_URL", job.GitInfo.RepoURL, true, true, false},
{"CI_COMMIT_REF", job.GitInfo.Sha, true, true, false},
{"CI_COMMIT_BEFORE_SHA", job.GitInfo.BeforeSha, true, true, false},
{"CI_COMMIT_REF_NAME", job.GitInfo.Ref, true, true, false},
}
return
}
func (c *GitLabCiYamlParser) buildVariables(configVariables interface{}) (buildVariables common.JobVariables, err error) {
if variables, ok := configVariables.(map[string]interface{}); ok {
for key, value := range variables {
......@@ -166,11 +187,21 @@ func (c *GitLabCiYamlParser) buildVariables(configVariables interface{}) (buildV
func (c *GitLabCiYamlParser) prepareVariables(job *common.JobResponse) (err error) {
job.Variables = common.JobVariables{}
job.Variables, err = c.buildVariables(c.config["variables"])
defaultVariables, err := c.buildDefaultVariables(job)
if err != nil {
return
}
job.Variables = append(job.Variables, defaultVariables...)
globalVariables, err := c.buildVariables(c.config["variables"])
if err != nil {
return
}
job.Variables = append(job.Variables, globalVariables...)
jobVariables, err := c.buildVariables(c.jobConfig["variables"])
if err != nil {
return
......
......@@ -347,7 +347,7 @@ func getRequestJobResponse() (res map[string]interface{}) {
cache := make([]map[string]interface{}, 1)
cache[0] = make(map[string]interface{})
cache[0]["key"] = "$CI_BUILD_REF"
cache[0]["key"] = "$CI_COMMIT_REF"
cache[0]["untracked"] = false
cache[0]["paths"] = []string{"vendor/*"}
res["cache"] = cache
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment