Runner in docker image fails with: /bin/sh: 3: set: Illegal option -o pipefail

Summary

I have set up a project using Nu HTML Checker to validate HTML files as part of CI. When the CI runs, it fails with the message:

/bin/sh: 3: set: Illegal option -o pipefail

I see some other issues which trace this back to a "bashism" in Gitlab Runner code. The issue has been around for a long time. Suggested workaround entrypoint: [], entrypoint: [""], and entrypoint: ["/bin/bash"] don't work for me, so I'm creating this issue in hopes someone can advise a workaround for my example.

Steps to reproduce

I set up a barebones repository to reproduce the issue here. Feel free to clone, fork, etc.

.gitlab-ci.yml
variables:
  GIT_DEPTH: 1

stages:
  - test

check:html:
  image: 
    name: ghcr.io/validator/validator:latest
    entrypoint: [""]
  stage: test
  script:
    - >
        vnu --format text --errors-only --skip-non-html src

Actual behavior

Runner fails with error.

Expected behavior

Runner runs the validator.

Relevant logs and/or screenshots

job log
Running with gitlab-runner 14.3.0-rc1 (ed15bfbf)
  on docker-auto-scale 0277ea0f
Resolving secrets 00:00
Preparing the "docker+machine" executor 00:09
Using Docker executor with image ghcr.io/validator/validator:latest ...
Pulling docker image ghcr.io/validator/validator:latest ...
Using docker image sha256:3770f6bdc06a592f46b066daaea4b9e9923c3c10eeac7eb66f44fcd74a060eee for ghcr.io/validator/validator:latest with digest ghcr.io/validator/validator@sha256:c796b50f442cf2b2811b5f62dae9f71e236a7ded1237b232d16a532606faaed3 ...
Preparing environment 00:01
Running on runner-0277ea0f-project-29977066-concurrent-0 via runner-0277ea0f-srm-1632848293-727151a0...
Getting source from Git repository 00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 1...
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /builds/cheryllium/runner-test/.git/
Created fresh repository.
Checking out 1cac339c as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:00
Using docker image sha256:3770f6bdc06a592f46b066daaea4b9e9923c3c10eeac7eb66f44fcd74a060eee for ghcr.io/validator/validator:latest with digest ghcr.io/validator/validator@sha256:c796b50f442cf2b2811b5f62dae9f71e236a7ded1237b232d16a532606faaed3 ...
/bin/sh: 3: set: Illegal option -o pipefail
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 2

Environment description

Shared Runners on GitLab.com.

Used GitLab Runner version

Running with gitlab-runner 14.3.0-rc1 (ed15bfbf)
  on docker-auto-scale 0277ea0f

Possible fixes

I could not find a successful workaround for my own use case. This post gives a summary and links to several issues with the same root cause: https://forum.gitlab.com/t/custom-docker-image-fails-with-illegal-option-pipefail-in-the-gitlab-script/31359/5

Some workarounds others have suggested include:

  • Override the docker image entrypoint: entrypoint: [""], entrypoint: ["/bin/bash", "-c"]
  • Install bash into the docker image

In a nutshell, it looks like the problem is that Gitlab Runner requires Bash to exist in the environment, but this is not always the case. It would be ideal if Gitlab Runner could at least catch and handle this error.

I understand that removing "bashisms" altogether is much easier said than done. Looks like there is an MR in progress to address it here: !3014 (merged)

I'd love any advice on finding a successful workaround for my use case in the meantime. Thank you.