Script function
Step-runner part in GitLab Runner "script" execution as a Step (step-runner!336 - closed) • Georgi N. Georgiev | GitLab • 18.8
This MR implements the specifics of a gitlab-runner's "script" execution in a self-contained step.
It does so by running a shell script with all commands written inside.
The shell script ports all important functionality from gitlab-runner's script while offloading functionality to the Go environment where possible.
Important: Only bash and sh is ported as we were looking for a minimal solution at this point
Functionality ported as a script:
- setting pipefail to work with both bash and sh
- xtrace as a setting that can be passed by gitlab-runner according to CI_DEBUG_TRACE -
debug_trace - set -o errexit
- FF_ENABLE_BASH_EXIT_CODE_CHECK as an input setting which can be set by gitlab-runner -
check_for_errors - FF_POSIXLY_CORRECT_ESCAPES through
posix_escape - FF_SCRIPT_SECTIONS -
trace_sections
These implementations are rather minimal and do not add a lot of complexity IMO
Functionality delegated to the Go environment:
- Env variables - no
export X=A - Working directory - no
cd X - Shell detection in the same order as gitlab-runner
Usage
spec:
---
run:
- name: basic_commands
step: builtin://script_legacy
inputs:
script:
- echo "Hello from script_legacy"
- pwd
- date
- echo "Basic test complete"
script ⚠️
The script accepts an array of commands. The script of gitlab-runner and the original script step accept a string as well. It is a matter of how this step will be used.
- If the step will be used only by gitlab-runner receiving only the list might be fine
- If the step will be a replacement for the existing script we can accept a simple string too
Accepting suggestions.
Testing
There's unit and integration tests
There's also e2e tests which run the same script against this step and a regular gitlab-runner: https://gitlab.com/ggeorgiev_gitlab/steps-runner-script-e2e/-/pipelines/2216070595.
Verification is not automatic at this point as I am not sure if this is something we'd want to keep. In any case it was useful to test this myself. Accepting suggestions.
Alternatively, when The runner can decide whether to dispatch scrip... (step-runner#289 - closed) • Arran Walker • 18.9 is ready we can replace any script we already have in other places such as gitlab-runner itself to test this in a real-world scenario without doing a bajilion e2e tests. I see step runner has e2e tests but nothing that tests the output against gitlab-runner.
We can also easily add e2e tests to test all settings flags depending on the approach we choose.
PWSH and Powershell
Currently left out as the goal was to have the minimal viable implementation. I have not left pwsh/powershell stubs as I didn't want to leave dead code, the code assumes only bash/sh right now.