Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script mode set -xe by default when no shebang used #1736

Merged
merged 1 commit into from Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand Down
8 changes: 4 additions & 4 deletions pkg/pod/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/pod/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`},
Expand Down