# Does circleci step halt works with version 2.1?

**URL:** <https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674>\
**Category:** Build Environment\
**Created:** [July 13, 2020, 8:22pm UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674 "2020-07-13T20:22:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gg-caylent](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/gg-caylent/32/25275_2.png) [@gg-caylent](https://discuss.circleci.com/u/gg-caylent)\
**Post date:** [July 13, 2020, 8:22pm UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/1 "2020-07-13T20:22:20Z")

</div>

Hi everyone,

Basically I’m trying to use `circleci step halt` to stop a workflow at a given point, but I don’t see it doing anything or even erroring out, maybe I’m not using it correctly or it is not supported in 2.1? Is there any alternative way of accomplishing something like this without failing the job?

This is the config I’m testing with:

```auto
version: 2.1

orbs:
  hello: circleci/hello-build@0.0.5
  build-tools: circleci/build-tools@2.6.3

jobs:
  build:
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - setup_remote_docker
      - build-tools/install-ci-tools
      - run: |
            if [[$(echo "$CIRCLE_PULL_REQUEST $CIRCLE_PULL_REQUESTS" | grep -c "pull") -gt 0]]; then
              echo "a PR staph!"
              circleci step halt
              circleci-agent step halt
              exit 0
            else
              echo "not a PR"
            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\/.*$/

```

Thanks.

---

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mike/32/24230_2.png) [@mike](https://discuss.circleci.com/u/mike)\
**Post date:** [July 13, 2020, 9:52pm UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/2 "2020-07-13T21:52:05Z")

</div>

You should be able to stop a job via `circleci-agent step halt` with 2.1

[https://circleci.com/docs/2.0/configuration-reference/#ending-a-job-from-within-a-step](https://circleci.com/docs/2.0/configuration-reference/#ending-a-job-from-within-a-step)

Looking at your config, it looks like it is the last step in the `build` job. Therefore it would have the same effect as `exit 0`. The `halt` call will just prevent any later `steps` from running.

---

<div class="post-metadata">

**Author:** ![gg-caylent](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/gg-caylent/32/25275_2.png) [@gg-caylent](https://discuss.circleci.com/u/gg-caylent)\
**Post date:** [July 13, 2020, 10:12pm UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/3 "2020-07-13T22:12:13Z")

</div>

So it does execute in the correct order, I added the requires for that, but still the build continues as normal, see the image below:

 ![image](https://global.discourse-cdn.com/circleci/original/3X/d/5/d50f136a6765194e9a9e36796b81e572d0d471e0.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mike/32/24230_2.png) [@mike](https://discuss.circleci.com/u/mike)\
**Post date:** [July 14, 2020, 12:35am UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/4 "2020-07-14T00:35:50Z")

</div>

Ah, I see where the confusion might be.

`circleci-agent step halt` will return a green build for a single job while skipping all the remaining steps in that one specific job. The workflow will still continue to execute additional jobs. A _workflow_ is a collection of _jobs_ and a _job_ is a collection of _steps_.

`circleci-agent step halt` does not have any effect on the rest of the workflow.

If you want to prevent the remaining workflow from running, you would need to either fail the job or make use of the CircleCI API v2 and cancel the workflow.

> **[CircleCI API](https://circleci.com/docs/api/v2/#operation/cancelWorkflow)**
>
> This document page describes the resources that make up the CircleCI API v2.

---

<div class="post-metadata">

**Author:** ![gg-caylent](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/gg-caylent/32/25275_2.png) [@gg-caylent](https://discuss.circleci.com/u/gg-caylent)\
**Post date:** [July 14, 2020, 1:20pm UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/5 "2020-07-14T13:20:03Z")

</div>

Awesome, that worked, for future reference this is how I did it:

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:

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

```

And that’s it, if that runs you should see something like this:

 ![image](https://global.discourse-cdn.com/circleci/original/3X/b/5/b5c9c83ef92658cb348591633f2c3c6404ed56a2.png)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [July 24, 2020, 1:20pm UTC](https://discuss.circleci.com/t/does-circleci-step-halt-works-with-version-2-1/36674/6 "2020-07-24T13:20:12Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
