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?
2
Answers
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.
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