0

I am using the docker:stable image to run the gitlab job.

  image: "docker:stable"
  services:
    - docker:dind
  before_script:
    - apk update
    - apk add py-pip jq bash
    - pip install awscli
- |
      if [[ $CI_COMMIT_MESSAGE = *"_check"* ]]; then

I am seeing the following error in the pipeline log.

$ if [[ $CI_COMMIT_MESSAGE = *"_check"* ]]; then # collapsed multi-line command 
sh: -Committing: unknown operand

Does anyone know why I am getting unknown operand or any tips how to capture and fix it?

RamK
  • 99
  • 2
  • 8
  • `[[` is a `bash` extension, the command is being executed using `sh`. – Barmar Dec 07 '22 at 22:51
  • 2
    ...a weird Frankenstein shell provided by [busybox](http://busybox.net/) that supports the `[[` operator, but apparently as an alias for `[`. You need to quote your variables, and you won't be able to perform glob matching (use a `case` statement for that if you need it). – larsks Dec 07 '22 at 23:02

1 Answers1

0

Instead of the regexp within the "[[" operator, you need to replace the "=" or "==" with the pattern-match operator, "=~", as follows:

#!/bin/bash

function pl() {
    sed -n "/${1}/p" ${2}
}

cat >log3 <<EnDoFiNpUt
ISTA00TUR_R_20190910000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190920000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190930000_01D_30S_MO.crx.gz
EnDoFiNpUt

CI_COMMIT_MESSAGE="reasearch_check_zone"

if [[ "${CI_COMMIT_MESSAGE}" =~ "_check" ]]
then    
    ### match on string pattern "93"
    pl 93 log3
fi
Eric Marceau
  • 1,601
  • 1
  • 8
  • 11