runconfig: set task default shell

Currently, if no shell is defined in the task and in the step, the executor will
use an hardcoded default shell.

This will cause changed run behavior if we add an option to globally set the
agola default shell.

To avoid this set the task shell to the default shell inside the runconfig if
it's empty so future executions will always use this value.
This commit is contained in:
Simone Gotti 2019-09-11 15:17:38 +02:00
parent 512fdb361a
commit 51e9a32db7
3 changed files with 13 additions and 0 deletions

View File

@ -26,6 +26,10 @@ import (
errors "golang.org/x/xerrors"
)
const (
defaultShell = "/bin/sh -e"
)
func genRuntime(c *config.Config, ce *config.Runtime, variables map[string]string) *rstypes.Runtime {
containers := []*rstypes.Container{}
for _, cc := range ce.Containers {
@ -206,6 +210,10 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string
DockerRegistriesAuth: make(map[string]rstypes.DockerRegistryAuth),
}
if t.Shell == "" {
t.Shell = defaultShell
}
if c.DockerRegistriesAuth != nil {
for regname, auth := range c.DockerRegistriesAuth {
t.DockerRegistriesAuth[regname] = rstypes.DockerRegistryAuth{

View File

@ -801,6 +801,7 @@ func TestGenRunConfig(t *testing.T) {
},
},
},
Shell: "/bin/sh -e",
Environment: map[string]string{
"ENV01": "ENV01",
"ENVFROMVARIABLE01": "VARVALUE01",
@ -876,6 +877,7 @@ func TestGenRunConfig(t *testing.T) {
},
},
},
Shell: "/bin/sh -e",
Environment: map[string]string{},
Steps: rstypes.Steps{
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "command01"}, Command: "command01", Environment: map[string]string{}},
@ -973,6 +975,7 @@ func TestGenRunConfig(t *testing.T) {
},
},
},
Shell: "/bin/sh -e",
Environment: map[string]string{},
Steps: rstypes.Steps{
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "command01"}, Command: "command01", Environment: map[string]string{}},

View File

@ -109,6 +109,8 @@ func (e *Executor) doRunStep(ctx context.Context, s *types.RunStep, t *types.Exe
}
defer outf.Close()
// TODO(sgotti) this line is used only for old runconfig versions that don't
// set a task default shell in the runconfig
shell := defaultShell
if t.Shell != "" {
shell = t.Shell