Search code examples
bashdockergitlabshgitlab-ci

Shell script unknown operand message in docker image


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?


Solution

  • 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