Slack notify breaking checkout in pre-steps?

I’ve been trying to get Slack integration going on our builds and ran into something that definitely feels like a bug. If you stick a pre-steps section into your aws-ecr/build-and-push-image job and try to send a slack notification (alerting users that the build has started), the build will fail in the checkout section with this error:

Directory (/home/circleci/project) you are trying to checkout to is not empty and not a git repository

Removing (or commenting out) the slack notify lets the job complete. A success/fail notification in post-steps does work.

Here is a partial snippet of my config.yml showing what I’m trying:

- aws-ecr/build-and-push-image:
          executor: ubuntu-small
          setup-remote-docker: true
          dockerfile: docker-build/Dockerfile
          context: aws-dev-context
          repo: builds
          create-repo: true
            - run:
                command: |
                  echo "TICKET=`expr match \"${CIRCLE_BRANCH}\" '\(XYZ-[0-9]*\)'`" >> $BASH_ENV
                  source $BASH_ENV
            - slack/notify:
                event: always
                custom: |
                    "blocks": [
                            "type": "section",
                            "text": {
                                "type": "mrkdwn",
                                "text": "*Branch build* #${CIRCLE_BUILD_NUM} started for ${CIRCLE_BRANCH}. <${TICKET}|${TICKET}>"
                            "type": "divider"
            - slack/notify:
                event: pass
                template: basic_success_1
            - slack/notify:
                event: fail
                template: basic_fail_1

Unless you are using a self-hosted runner and want files to be available across builds you can use the following after you call slack (which I have defined as a command for easy calling)

It just clears the working directory of all files and I guess the slack orb creates a file, but does not clean up afterwards.

- run: rm -rf * || true
- run: rm -rf .* || true

1 Like