diff --git a/docs/tasks.md b/docs/tasks.md index 4d561b70fa5..863521760c6 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -156,11 +156,16 @@ If this field is present, the step cannot specify `command`. When specified, a `script` gets invoked as if it were the contents of a file in the container. Any `args` are passed to the script file. -Scripts that do not start with a shebang -[shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) line will use a default -value of `#!/bin/sh`, although users can override this by starting their script -with a shebang to declare what tool should be used to interpret the script. -That tool must then also be available within the step's container. +Scripts that do not start with a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) +line will use the following default preamble: + +```bash +#!/bin/sh +set -xe +``` +Users can override this by starting their script with a shebang to declare what +tool should be used to interpret the script. That tool must then also be +available within the step's container. This allows you to execute a Bash script, if the image includes `bash`: diff --git a/pkg/pod/script.go b/pkg/pod/script.go index 27ae7d10104..492a8e5e8a8 100644 --- a/pkg/pod/script.go +++ b/pkg/pod/script.go @@ -27,9 +27,9 @@ import ( ) const ( - scriptsVolumeName = "scripts" - scriptsDir = "/tekton/scripts" - defaultShebang = "#!/bin/sh\n" + scriptsVolumeName = "scripts" + scriptsDir = "/tekton/scripts" + defaultScriptPreamble = "#!/bin/sh\nset -xe\n" ) var ( @@ -77,7 +77,7 @@ func convertScripts(shellImage string, steps []v1alpha1.Step) (*corev1.Container script := s.Script if !hasShebang { - script = defaultShebang + s.Script + script = defaultScriptPreamble + s.Script } // At least one step uses a script, so we should return a diff --git a/pkg/pod/script_test.go b/pkg/pod/script_test.go index 3c16e75b0a3..cd2ac86583d 100644 --- a/pkg/pod/script_test.go +++ b/pkg/pod/script_test.go @@ -101,6 +101,7 @@ tmpfile="/tekton/scripts/script-3-j2tds" touch ${tmpfile} && chmod +x ${tmpfile} cat > ${tmpfile} << 'script-heredoc-randomly-generated-vr6ds' #!/bin/sh +set -xe no-shebang script-heredoc-randomly-generated-vr6ds `},