Job exits out as "succeeded" but not all images are pushed and no error output

I’m creating this thread because this is the first time after long time I’ve encountered issue with GitLab’s CI runner.

I’m using GitLab’s CI tool to push Docker images into ECR on AWS and the job exits out as “succeeded” but not all images are pushed. And I get no errors output to analyze.

Please ask for any details. I’m happy to provide screenshots as well.

part of my “pusher” script:

  if [ "$GITLAB_BRANCH" == "staging" ] || \
     [ "$GITLAB_BRANCH" == "production" ]
  then
    docker build $USERS_REPO -t $USERS:$COMMIT -f Dockerfile-$DOCKER_ENV
    docker tag $USERS:$COMMIT $REPO/$USERS:$TAG
    docker push $REPO/$USERS:$TAG

    docker build $USERS_DB_REPO -t $USERS_DB:$COMMIT -f Dockerfile
    docker tag $USERS_DB:$COMMIT $REPO/$USERS_DB:$TAG
    docker push $REPO/$USERS_DB:$TAG

    docker build $SWAGGER_REPO -t $SWAGGER:$COMMIT -f Dockerfile-$DOCKER_ENV
    docker tag $SWAGGER:$COMMIT $REPO/$SWAGGER:$TAG
    docker push $REPO/$SWAGGER:$TAG

    echo "building the client image ..."    # executed
    docker -D build $CLIENT_REPO -t $CLIENT:$COMMIT -f Dockerfile-prod --build-arg REACT_APP_USERS_SERVICE_URL=""    # something happens here but no error output
    echo "tagging the client image ..."       # skipped
    docker -D tag $CLIENT:$COMMIT $REPO/$CLIENT:$TAG   # skipped
    echo "pushing the client image ..."   # skipped
    docker -D push 274725968600.dkr.ecr.eu-west-2.amazonaws.com/test-driven-client:production   # skipped
  fi
fi

Hi,

each command line executes with an error code. You can capture that with calling echo $? directly afterwards. Based on that assumption, you can add error handling for these commands, e.g. if the exit code is not 0, then you 1) print an error 2) call exit explicitly with sthe returned exit code.

Best is to look into bash programming howtos for error handling strategies.

Cheers,
Michael

Hi,

thank you so much for the feedback. Would you mind sharing an example of the echo statement I should use ? Sorry, I’m asking because I’m well rounded in Python not in shell programming. I’m working on this project and learning shell syntax along the way.

I know echo function can be used like this echo "this is going to be printed out" but I’m unsure about how do you print out a value from a Docker command ?

My guess would be:

echo docker -D build $CLIENT_REPO -t $CLIENT:$COMMIT -f Dockerfile-prod --build-arg REACT_APP_USERS_SERVICE_URL=""

Is that right ?

I noticed something interesting. When I run CI on these images for pushing, first 3 images (users, users_db and swagger) get pushed into ECR and client image is left out,
but when I move client image to be first of the images nothing gets pushed into ECR ! Not even the other 3 images. That’s bizarre.

Hi,

Yesterday I was on my iPad hence my short answer. I’m not a heavy shell programmer either, I google a lot. In this case for shell capture exit code from command. Found this nice introduction:

So, with regard to the commands you are using, you should check for the error code from the last command.

docker -D build $CLIENT_REPO -t $CLIENT:$COMMIT -f Dockerfile-prod --build-arg REACT_APP_USERS_SERVICE_URL=""

if [ $? -ne 0 ]
then
  echo "FAILURE: .... Exiting now."
  exit 1
fi

You’ll need to find a way to make the command log more errors too. Since I don’t know how I’ll leave this exercise to you reading about Docker log levels on the CLI.

Cheers,
Michael

1 Like