0

Written a below gitlab pipeline using python image and if condition works perfectly fine.

.chk-bracket:
  image: "python:3.7"
  before_script:
    - apt update
    - apt install jq -y 
    - pip install awscli
    
  script:
    - echo $CI_COMMIT_MESSAGE
    - |
      if [[ $CI_COMMIT_MESSAGE = *"_test"* ]]; then
        echo "testing"
      fi
  rules:
    - if: $CI_COMMIT_BRANCH =~ /^develop/ && $CI_COMMIT_MESSAGE =~ /.*build_test.*/

Later we refactored to use docker image instead of python image and the if condition started failing, it's not printing testing. Of course I simplified with the simple if condition in the original complex gitlab pipeline code

.chk-bracket:
  image: "docker:stable"
  before_script:
    - apk update
    - apk add py-pip jq bash
    - pip install awscli
  script:
    - echo $CI_COMMIT_MESSAGE
    - |
      if [[ $CI_COMMIT_MESSAGE = *"_test"* ]]; then
        echo "testing"
      fi
  rules:
    - if: $CI_COMMIT_BRANCH =~ /^develop/ && $CI_COMMIT_MESSAGE =~ /.*build_test.*/

Any clues to why this condition is not working in docker image?

gcpdev-guy
  • 460
  • 1
  • 10
  • 23

2 Answers2

2

This is because python:3.7 uses debian as its base image and docker:stable uses alpine as its base image, Alpine comes with ash as the default shell instead of bash. I am using below statements inside docker image for substring match.

        if [ -z "${CI_COMMIT_TAG##*"dev"*}" ]; then
          echo "Building dev Image..."
          docker build --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG . --build-arg VERSION=$CI_COMMIT_TAG
        fi
antoniomerlin
  • 521
  • 1
  • 7
  • 17
1

As outlined by @antoniomerlin the dind image is alpine.

There is a ubuntu-dind version and there are maybe more ...

Installing aws cli (v2) in alpine is a real pain, there is already a detailed answer how to do that

Bash Stack
  • 509
  • 3
  • 12