Commit cbb74b17 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Rename common.BuildVariables to common.JobVariables

parent cf05b340
......@@ -361,8 +361,8 @@ func (b *Build) String() string {
return helpers.ToYAML(b)
}
func (b *Build) GetDefaultVariables() BuildVariables {
return BuildVariables{
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},
......@@ -381,7 +381,7 @@ func (b *Build) GetDefaultVariables() BuildVariables {
}
}
func (b *Build) GetAllVariables() (variables BuildVariables) {
func (b *Build) GetAllVariables() (variables JobVariables) {
if b.Runner != nil {
variables = append(variables, b.Runner.GetVariables()...)
}
......
......@@ -224,7 +224,7 @@ func TestGetSourcesRunFailure(t *testing.T) {
},
}
build.Variables = append(build.Variables, BuildVariable{Key: "GET_SOURCES_ATTEMPTS", Value: "3"})
build.Variables = append(build.Variables, JobVariable{Key: "GET_SOURCES_ATTEMPTS", Value: "3"})
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.EqualError(t, err, "build fail")
}
......@@ -262,7 +262,7 @@ func TestArtifactDownloadRunFailure(t *testing.T) {
},
}
build.Variables = append(build.Variables, BuildVariable{Key: "ARTIFACT_DOWNLOAD_ATTEMPTS", Value: "3"})
build.Variables = append(build.Variables, JobVariable{Key: "ARTIFACT_DOWNLOAD_ATTEMPTS", Value: "3"})
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.EqualError(t, err, "build fail")
}
......@@ -300,7 +300,7 @@ func TestRestoreCacheRunFailure(t *testing.T) {
},
}
build.Variables = append(build.Variables, BuildVariable{Key: "RESTORE_CACHE_ATTEMPTS", Value: "3"})
build.Variables = append(build.Variables, JobVariable{Key: "RESTORE_CACHE_ATTEMPTS", Value: "3"})
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.EqualError(t, err, "build fail")
}
......@@ -337,7 +337,7 @@ func TestRunWrongAttempts(t *testing.T) {
},
}
build.Variables = append(build.Variables, BuildVariable{Key: "GET_SOURCES_ATTEMPTS", Value: "0"})
build.Variables = append(build.Variables, JobVariable{Key: "GET_SOURCES_ATTEMPTS", Value: "0"})
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.EqualError(t, err, "Number of attempts out of the range [1, 10] for stage: get_sources")
}
......@@ -374,7 +374,7 @@ func TestRunSuccessOnSecondAttempt(t *testing.T) {
},
}
build.Variables = append(build.Variables, BuildVariable{Key: "GET_SOURCES_ATTEMPTS", Value: "3"})
build.Variables = append(build.Variables, JobVariable{Key: "GET_SOURCES_ATTEMPTS", Value: "3"})
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.NoError(t, err)
}
......@@ -305,8 +305,8 @@ func (c *RunnerConfig) String() string {
return fmt.Sprintf("%v url=%v token=%v executor=%v", c.Name, c.URL, c.Token, c.Executor)
}
func (c *RunnerConfig) GetVariables() BuildVariables {
var variables BuildVariables
func (c *RunnerConfig) GetVariables() JobVariables {
var variables JobVariables
for _, environment := range c.Environment {
if variable, err := ParseVariable(environment); err == nil {
......
......@@ -194,20 +194,20 @@ type Dependency struct {
type Dependencies []Dependency
type JobResponse struct {
ID int `json:"id"`
Token string `json:"token"`
AllowGitFetch bool `json:"allow_git_fetch"`
JobInfo JobInfo `json:"job_info"`
GitInfo GitInfo `json:"git_info"`
RunnerInfo RunnerInfo `json:"runner_info"`
Variables BuildVariables `json:"variables"` // TODO: Rename BuildVariables to JobVariables
Steps Steps `json:"steps"`
Image Image `json:"image"`
Services Services `json:"services"`
Artifacts Artifacts `json:"artifacts"`
Cache Caches `json:"cache"`
Credentials []Credentials `json:"credentials"`
Dependencies Dependencies `json:"dependencies"`
ID int `json:"id"`
Token string `json:"token"`
AllowGitFetch bool `json:"allow_git_fetch"`
JobInfo JobInfo `json:"job_info"`
GitInfo GitInfo `json:"git_info"`
RunnerInfo RunnerInfo `json:"runner_info"`
Variables JobVariables `json:"variables"`
Steps Steps `json:"steps"`
Image Image `json:"image"`
Services Services `json:"services"`
Artifacts Artifacts `json:"artifacts"`
Cache Caches `json:"cache"`
Credentials []Credentials `json:"credentials"`
Dependencies Dependencies `json:"dependencies"`
TLSCAChain string `json:"-"`
}
......
......@@ -7,7 +7,7 @@ import (
"strings"
)
type BuildVariable struct {
type JobVariable struct {
Key string `json:"key"`
Value string `json:"value"`
Public bool `json:"public"`
......@@ -15,13 +15,13 @@ type BuildVariable struct {
File bool `json:"file"`
}
type BuildVariables []BuildVariable
type JobVariables []JobVariable
func (b BuildVariable) String() string {
func (b JobVariable) String() string {
return fmt.Sprintf("%s=%s", b.Key, b.Value)
}
func (b BuildVariables) PublicOrInternal() (variables BuildVariables) {
func (b JobVariables) PublicOrInternal() (variables JobVariables) {
for _, variable := range b {
if variable.Public || variable.Internal {
variables = append(variables, variable)
......@@ -30,14 +30,14 @@ func (b BuildVariables) PublicOrInternal() (variables BuildVariables) {
return variables
}
func (b BuildVariables) StringList() (variables []string) {
func (b JobVariables) StringList() (variables []string) {
for _, variable := range b {
variables = append(variables, variable.String())
}
return variables
}
func (b BuildVariables) Get(key string) string {
func (b JobVariables) Get(key string) string {
switch key {
case "$":
return key
......@@ -52,11 +52,11 @@ func (b BuildVariables) Get(key string) string {
return ""
}
func (b BuildVariables) ExpandValue(value string) string {
func (b JobVariables) ExpandValue(value string) string {
return os.Expand(value, b.Get)
}
func (b BuildVariables) Expand() (variables BuildVariables) {
func (b JobVariables) Expand() (variables JobVariables) {
for _, variable := range b {
variable.Value = b.ExpandValue(variable.Value)
variables = append(variables, variable)
......@@ -64,13 +64,13 @@ func (b BuildVariables) Expand() (variables BuildVariables) {
return variables
}
func ParseVariable(text string) (variable BuildVariable, err error) {
func ParseVariable(text string) (variable JobVariable, err error) {
keyValue := strings.SplitN(text, "=", 2)
if len(keyValue) != 2 {
err = errors.New("missing =")
return
}
variable = BuildVariable{
variable = JobVariable{
Key: keyValue[0],
Value: keyValue[1],
}
......
......@@ -8,7 +8,7 @@ import (
)
func TestVariablesJSON(t *testing.T) {
var x BuildVariable
var x JobVariable
data := []byte(`{"key": "FOO", "value": "bar", "public": true, "internal": true, "file": true}`)
err := json.Unmarshal(data, &x)
......@@ -21,15 +21,15 @@ func TestVariablesJSON(t *testing.T) {
}
func TestVariableString(t *testing.T) {
v := BuildVariable{"key", "value", false, false, false}
v := JobVariable{"key", "value", false, false, false}
assert.Equal(t, "key=value", v.String())
}
func TestPublicAndInternalVariables(t *testing.T) {
v1 := BuildVariable{"key", "value", false, false, false}
v2 := BuildVariable{"public", "value", true, false, false}
v3 := BuildVariable{"private", "value", false, true, false}
all := BuildVariables{v1, v2, v3}
v1 := JobVariable{"key", "value", false, false, false}
v2 := JobVariable{"public", "value", true, false, false}
v3 := JobVariable{"private", "value", false, true, false}
all := JobVariables{v1, v2, v3}
public := all.PublicOrInternal()
assert.NotContains(t, public, v1)
assert.Contains(t, public, v2)
......@@ -37,15 +37,15 @@ func TestPublicAndInternalVariables(t *testing.T) {
}
func TestListVariables(t *testing.T) {
v := BuildVariables{{"key", "value", false, false, false}}
v := JobVariables{{"key", "value", false, false, false}}
assert.Equal(t, []string{"key=value"}, v.StringList())
}
func TestGetVariable(t *testing.T) {
v1 := BuildVariable{"key", "key_value", false, false, false}
v2 := BuildVariable{"public", "public_value", true, false, false}
v3 := BuildVariable{"private", "private_value", false, false, false}
all := BuildVariables{v1, v2, v3}
v1 := JobVariable{"key", "key_value", false, false, false}
v2 := JobVariable{"public", "public_value", true, false, false}
v3 := JobVariable{"private", "private_value", false, false, false}
all := JobVariables{v1, v2, v3}
assert.Equal(t, "public_value", all.Get("public"))
assert.Empty(t, all.Get("other"))
......@@ -54,7 +54,7 @@ func TestGetVariable(t *testing.T) {
func TestParseVariable(t *testing.T) {
v, err := ParseVariable("key=value=value2")
assert.NoError(t, err)
assert.Equal(t, BuildVariable{"key", "value=value2", false, false, false}, v)
assert.Equal(t, JobVariable{"key", "value=value2", false, false, false}, v)
}
func TestInvalidParseVariable(t *testing.T) {
......@@ -63,7 +63,7 @@ func TestInvalidParseVariable(t *testing.T) {
}
func TestVariablesExpansion(t *testing.T) {
all := BuildVariables{
all := JobVariables{
{"key", "value_of_$public", false, false, false},
{"public", "some_value", true, false, false},
{"private", "value_of_${public}", false, false, false},
......@@ -79,7 +79,7 @@ func TestVariablesExpansion(t *testing.T) {
}
func TestSpecialVariablesExpansion(t *testing.T) {
all := BuildVariables{
all := JobVariables{
{"key", "$$", false, false, false},
{"key2", "$/dsa", true, false, false},
{"key3", "aa$@bb", false, false, false},
......
......@@ -263,7 +263,7 @@ func TestDockerPrivilegedServiceAccessingBuildsFolder(t *testing.T) {
Name: "docker:dind",
},
}
build.Variables = append(build.Variables, common.BuildVariable{
build.Variables = append(build.Variables, common.JobVariable{
Key: "GIT_STRATEGY", Value: strategy,
})
......
......@@ -506,8 +506,8 @@ func addGitLabRegistryCredentials(e *executor) {
}
func addRemoteVariableCredentials(e *executor) {
e.Build.Variables = common.BuildVariables{
common.BuildVariable{
e.Build.Variables = common.JobVariables{
common.JobVariable{
Key: "DOCKER_AUTH_CONFIG",
Value: testVariableAuthConfigs,
},
......
......@@ -189,7 +189,7 @@ func TestPrepare(t *testing.T) {
Image: common.Image{
Name: "test-image",
},
Variables: []common.BuildVariable{
Variables: []common.JobVariable{
{Key: "privileged", Value: "true"},
},
},
......@@ -250,7 +250,7 @@ func TestPrepare(t *testing.T) {
Image: common.Image{
Name: "test-image",
},
Variables: []common.BuildVariable{
Variables: []common.JobVariable{
{Key: "KUBERNETES_NAMESPACE_OVERWRITE", Value: "namespacee"},
},
},
......@@ -314,7 +314,7 @@ func TestPrepare(t *testing.T) {
Image: common.Image{
Name: "test-image",
},
Variables: []common.BuildVariable{
Variables: []common.JobVariable{
{Key: "privileged", Value: "true"},
},
},
......@@ -360,7 +360,7 @@ func TestPrepare(t *testing.T) {
Image: common.Image{
Name: "test-image",
},
Variables: []common.BuildVariable{
Variables: []common.JobVariable{
{Key: "KUBERNETES_NAMESPACE_OVERWRITE", Value: "namespace"},
},
},
......@@ -571,7 +571,7 @@ func TestSetupBuildPod(t *testing.T) {
BuildShell: &common.ShellConfiguration{},
Build: &common.Build{
JobResponse: common.JobResponse{
Variables: []common.BuildVariable{},
Variables: []common.JobVariable{},
},
Runner: &common.RunnerConfig{},
},
......@@ -766,7 +766,7 @@ func TestOverwriteNamespaceNotMatch(t *testing.T) {
Image: common.Image{
Name: "test-image",
},
Variables: []common.BuildVariable{
Variables: []common.JobVariable{
{Key: "KUBERNETES_NAMESPACE_OVERWRITE", Value: "namespace"},
},
},
......
......@@ -211,7 +211,7 @@ func limits(cpu, memory string) (api.ResourceList, error) {
// buildVariables converts a common.BuildVariables into a list of
// kubernetes EnvVar objects
func buildVariables(bv common.BuildVariables) []api.EnvVar {
func buildVariables(bv common.JobVariables) []api.EnvVar {
e := make([]api.EnvVar, len(bv))
for i, b := range bv {
e[i] = api.EnvVar{
......
......@@ -165,9 +165,9 @@ func TestBuildWithShallowLock(t *testing.T) {
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, []common.BuildVariable{
common.BuildVariable{Key: "GIT_DEPTH", Value: "1"},
common.BuildVariable{Key: "GIT_STRATEGY", Value: "fetch"}}...)
build.Variables = append(build.Variables, []common.JobVariable{
common.JobVariable{Key: "GIT_DEPTH", Value: "1"},
common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"}}...)
err = runBuild(t, build)
assert.NoError(t, err)
......@@ -187,7 +187,7 @@ func TestBuildWithGitStrategyNone(t *testing.T) {
defer cleanup()
build.Runner.PreCloneScript = "echo pre-clone-script"
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_STRATEGY", Value: "none"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "none"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -206,7 +206,7 @@ func TestBuildWithGitStrategyFetch(t *testing.T) {
defer cleanup()
build.Runner.PreCloneScript = "echo pre-clone-script"
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_STRATEGY", Value: "fetch"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -228,7 +228,7 @@ func TestBuildWithGitStrategyClone(t *testing.T) {
defer cleanup()
build.Runner.PreCloneScript = "echo pre-clone-script"
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_STRATEGY", Value: "clone"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "clone"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -251,7 +251,7 @@ func TestBuildWithGitSubmoduleStrategyNone(t *testing.T) {
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "none"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "none"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -276,7 +276,7 @@ func TestBuildWithGitSubmoduleStrategyNormal(t *testing.T) {
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "normal"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "normal"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -299,7 +299,7 @@ func TestBuildWithGitSubmoduleStrategyRecursive(t *testing.T) {
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "recursive"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "recursive"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -322,7 +322,7 @@ func TestBuildWithGitSubmoduleStrategyInvalid(t *testing.T) {
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "invalid"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "invalid"})
out, err := runBuildReturningOutput(t, build)
assert.EqualError(t, err, "unknown GIT_SUBMODULE_STRATEGY")
......@@ -339,8 +339,8 @@ func TestBuildWithGitSubmoduleStrategyRecursiveAndGitStrategyNone(t *testing.T)
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_STRATEGY", Value: "none"})
build.Variables = append(build.Variables, common.BuildVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "recursive"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "none"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "recursive"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
......@@ -365,7 +365,7 @@ func TestBuildWithDebugTrace(t *testing.T) {
assert.NoError(t, err)
assert.NotRegexp(t, `[^$] echo Hello World`, out)
build.Variables = append(build.Variables, common.BuildVariable{Key: "CI_DEBUG_TRACE", Value: "true"})
build.Variables = append(build.Variables, common.JobVariable{Key: "CI_DEBUG_TRACE", Value: "true"})
out, err = runBuildReturningOutput(t, build)
assert.NoError(t, err)
......
......@@ -144,11 +144,11 @@ func (c *GitLabCiYamlParser) prepareSteps(job *common.JobResponse) (err error) {
return
}
func (c *GitLabCiYamlParser) buildVariables(configVariables interface{}) (buildVariables common.BuildVariables, err error) {
func (c *GitLabCiYamlParser) buildVariables(configVariables interface{}) (buildVariables common.JobVariables, err error) {
if variables, ok := configVariables.(map[string]interface{}); ok {
for key, value := range variables {
if valueText, ok := value.(string); ok {
buildVariables = append(buildVariables, common.BuildVariable{
buildVariables = append(buildVariables, common.JobVariable{
Key: key,
Value: valueText,
Public: true,
......@@ -165,7 +165,7 @@ func (c *GitLabCiYamlParser) buildVariables(configVariables interface{}) (buildV
}
func (c *GitLabCiYamlParser) prepareVariables(job *common.JobResponse) (err error) {
job.Variables = common.BuildVariables{}
job.Variables = common.JobVariables{}
job.Variables, err = c.buildVariables(c.config["variables"])
if err != nil {
return
......
......@@ -30,7 +30,7 @@ func (b *AbstractShell) writeExports(w ShellWriter, info common.ShellScriptInfo)
func (b *AbstractShell) writeTLSCAInfo(w ShellWriter, build *common.Build, key string) {
if build.TLSCAChain != "" {
w.Variable(common.BuildVariable{
w.Variable(common.JobVariable{
Key: key,
Value: build.TLSCAChain,
Public: true,
......
......@@ -78,7 +78,7 @@ func (b *BashWriter) buildCommand(command string, arguments ...string) string {
return strings.Join(list, " ")
}
func (b *BashWriter) Variable(variable common.BuildVariable) {
func (b *BashWriter) Variable(variable common.JobVariable) {
if variable.File {
variableFile := b.Absolute(path.Join(b.TemporaryPath, variable.Key))
b.Line(fmt.Sprintf("mkdir -p %q", helpers.ToSlash(b.TemporaryPath)))
......
......@@ -101,7 +101,7 @@ func (b *CmdWriter) buildCommand(command string, arguments ...string) string {
return strings.Join(list, " ")
}
func (b *CmdWriter) Variable(variable common.BuildVariable) {
func (b *CmdWriter) Variable(variable common.JobVariable) {
if variable.File {
variableFile := b.Absolute(path.Join(b.TemporaryPath, variable.Key))
variableFile = helpers.ToBackslash(variableFile)
......
......@@ -88,7 +88,7 @@ func (b *PsWriter) buildCommand(command string, arguments ...string) string {
return "& " + strings.Join(list, " ")
}
func (b *PsWriter) Variable(variable common.BuildVariable) {
func (b *PsWriter) Variable(variable common.JobVariable) {
if variable.File {
variableFile := b.Absolute(path.Join(b.TemporaryPath, variable.Key))
variableFile = helpers.ToBackslash(variableFile)
......
......@@ -3,7 +3,7 @@ package shells
import "gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
type ShellWriter interface {
Variable(variable common.BuildVariable)
Variable(variable common.JobVariable)
Command(command string, arguments ...string)
Line(text string)
CheckForErrors()
......
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