# Integrating CircleCI

Source: https://www.jawsdeploy.net/guides/integrating-circleci

Add a CircleCI job that promotes successful builds into Jaws Deploy and starts a deployment.

CircleCI talks to Jaws Deploy through the REST API. CircleCI doesn't ship PowerShell by default, so the cleanest path is a Linux job that calls `curl`.

## A `create_release` job after build and test

Store `JAWS_API_KEY` and `JAWS_SA_ID` as project environment variables.

```
version: 2.1
jobs:
  create_release:
    docker:
      - image: cimg/base:stable
    steps:
      - run:
          name: Create Jaws Deploy release
          command: |
            curl -X POST "https://app.jawsdeploy.net/api/workspaces/default/projects/checkout-service/releases" \
              -u "$JAWS_SA_ID:$JAWS_API_KEY" \
              -H "Content-Type: application/json" \
              -d "{
                \"version\":  \"$CIRCLE_BUILD_NUM\",
                \"packages\": { \"Checkout.Web\": \"$CIRCLE_BUILD_NUM\" }
              }"

workflows:
  build_and_release:
    jobs:
      - build
      - create_release:
          requires: [build]
          filters:
            branches:
              only: main
```

> **// Triggering a deployment too - Add a second API call to start a deployment to `Dev`.**
> 
> After release creation, POST to `/api/.../releases/{version}/deployments` with `{ "environment": "Dev" }`. That keeps the staging deploy automatic and leaves later environments gated inside Jaws Deploy.

