Skip to content

ci: Don't fail on unbound variable in .gitlab/ci/frontend.gitlab-ci.yml

What does this MR do and why?

Unbound variables raise an error even if the call is [[ -n "${UNBOUND_VARIABLE}" ]]. Changing this to [[ -n "${UNBOUND_VARIABLE:-}" ]] solves the problem (tested locally).

How to set up and validate locally

You can use the following script to test this locally. The following will raise a test.sh: line 5: CI_NODE_INDEX: unbound variable error:

#!/usr/bin/env bash

set -euo pipefail

if [[ -n "${CI_NODE_INDEX}" ]] && [[ "${CI_NODE_INDEX}" -ne 1 ]]; then
  echo "INFO: Removing 'tmp/tests/frontend' as we're on node ${CI_NODE_INDEX}.";
else
  echo "\${CI_NODE_INDEX} isn't set."
fi

While the following would just print ${CI_NODE_INDEX} isn't set.:

#!/usr/bin/env bash

set -euo pipefail

if [[ -n "${CI_NODE_INDEX:-}" ]] && [[ "${CI_NODE_INDEX}" -ne 1 ]]; then
  echo "INFO: Removing 'tmp/tests/frontend' as we're on node ${CI_NODE_INDEX}.";
else
  echo "\${CI_NODE_INDEX} isn't set."
fi

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #407588 (closed)

Edited by Rémy Coutable

Merge request reports

Loading