Allow to disable CI_DEBUG_TRACE support from the configuration file

parent 692ae235
Pipeline #54142506 passed with stages
in 58 minutes and 36 seconds
......@@ -687,6 +687,10 @@ func (b *Build) GetSubmoduleStrategy() SubmoduleStrategy {
}
func (b *Build) IsDebugTraceEnabled() bool {
if b.Runner.DebugTraceDisabled {
return false
}
trace, err := strconv.ParseBool(b.GetAllVariables().Get("CI_DEBUG_TRACE"))
if err != nil {
return false
......
......@@ -729,26 +729,53 @@ func TestRunSuccessOnSecondAttempt(t *testing.T) {
}
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{Key: "CI_DEBUG_TRACE", Value: "false", Public: true, Internal: true})
build = &Build{
JobResponse: successfulBuild,
testCases := map[string]struct {
debugTraceVariableValue string
expectedValue bool
debugTraceFeatureDisabled bool
}{
"variable not set": {
expectedValue: false,
},
"variable set to false": {
debugTraceVariableValue: "false",
expectedValue: false,
},
"variable set to true": {
debugTraceVariableValue: "true",
expectedValue: true,
},
"variable set to a non-bool value": {
debugTraceVariableValue: "xyz",
expectedValue: false,
},
"variable set to true and feature disabled from configuration": {
debugTraceVariableValue: "true",
expectedValue: false,
debugTraceFeatureDisabled: true,
},
}
assert.False(t, build.IsDebugTraceEnabled(), "IsDebugTraceEnabled should be false if CI_DEBUG_TRACE is set to false")
successfulBuild, err = GetSuccessfulBuild()
assert.NoError(t, err)
for testName, testCase := range testCases {
t.Run(testName, func(t *testing.T) {
build := &Build{
JobResponse: JobResponse{
Variables: JobVariables{},
},
Runner: &RunnerConfig{
RunnerSettings: RunnerSettings{
DebugTraceDisabled: testCase.debugTraceFeatureDisabled,
},
},
}
successfulBuild.Variables = append(successfulBuild.Variables, JobVariable{Key: "CI_DEBUG_TRACE", Value: "true", Public: true, Internal: true})
build = &Build{
JobResponse: successfulBuild,
if testCase.debugTraceVariableValue != "" {
build.Variables = append(build.Variables, JobVariable{Key: "CI_DEBUG_TRACE", Value: testCase.debugTraceVariableValue, Public: true})
}
assert.Equal(t, testCase.expectedValue, build.IsDebugTraceEnabled())
})
}
assert.True(t, build.IsDebugTraceEnabled(), "IsDebugTraceEnabled should be true if CI_DEBUG_TRACE is set to true")
}
func TestDefaultEnvVariables(t *testing.T) {
......
......@@ -276,6 +276,8 @@ type RunnerSettings struct {
PreBuildScript string `toml:"pre_build_script,omitempty" json:"pre_build_script" long:"pre-build-script" env:"RUNNER_PRE_BUILD_SCRIPT" description:"Runner-specific command script executed after code is pulled, just before build executes"`
PostBuildScript string `toml:"post_build_script,omitempty" json:"post_build_script" long:"post-build-script" env:"RUNNER_POST_BUILD_SCRIPT" description:"Runner-specific command script executed after code is pulled and just after build executes"`
DebugTraceDisabled bool `toml:"debug_trace_disabled,omitempty" json:"debug_trace_disabled" long:"debug-trace-disabled" env:"RUNNER_DEBUG_TRACE_DISABLED" description:"When set to true Runner will disable the possibility of using the CI_DEBUG_TRACE feature"`
Shell string `toml:"shell,omitempty" json:"shell" long:"shell" env:"RUNNER_SHELL" description:"Select bash, cmd or powershell"`
SSH *ssh.Config `toml:"ssh,omitempty" json:"ssh" group:"ssh executor" namespace:"ssh"`
......
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