circlecicircleci-2.0circleci-workflows

CircleCI: Skip entire workflow


Basically I'm trying to skip the build if it's not a pull request or a certain branch, however I don't seem to be able to skip a job or a part of the workflow if this fails, so far the problem is that circleci step halt does nothing in my pipelines, example config here:

version: 2.1

orbs:
  hello: circleci/hello-build@0.0.5

jobs:
  build:
    docker:
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - setup_remote_docker
      - run:
          command: |
            if [[ $(echo "$CIRCLE_PULL_REQUEST $CIRCLE_PULL_REQUESTS" | grep -c "pull") -gt 0 ]]; then
              echo "Do stuff if it's a PR"
            else
              echo "Not a PR, Skipping."
              circleci step halt # does nothing
              circleci-agent step halt # does nothing
              exit 0
            fi

workflows:
  "Hello Workflow":
    jobs:
      - hello/hello-build:
          requires:
            - build
          filters:
            branches:
              only:
                - testing
                - /^(?!pull\/).*$/
            tags:
              only:
                - /^pull\/.*$/
      - build:
          filters:
            branches:
              only:
                - testing
                - /^(?!pull\/).*$/
            tags:
              only:
                - /^pull\/.*$/

This does not fail, and it works on pull requests but the hello/hello-build is executed anyway despite the circleci step halt commands.

Any help would be appreciated, thanks!


Solution

  • After creating a thread in their forums this is what worked: https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/4

    Go to account settings -> Personal API Tokens -> New token. Once you have the token go to the project and create a new environment variable something like CIRCLE_TOKEN and save it there.

    Then in the config.yml you can run something like this to cancel the current workflow:

    curl -X POST https://circleci.com/api/v2/workflow/${CIRCLE_WORKFLOW_ID}/cancel -H 'Accept: application/json' -u '${CIRCLE_TOKEN}:'

    Then you will see something like: enter image description here