I have a workflow on CircleCi that builds and deploys a branch to AWS when a pull request is open from that branch.
I have a second workflow that tears down the deployed environment when the pull request is merged.
NOW: When a branch is deleted from Github, it is also deleted from CircleCi. And most of the times, when the developers in my team merge their pull request, they delete the branch.
When this happens, CircleCi tries to teardown the previously deployed environment. The problem now is that since the branch was deleted from Github and thus automatically deleted from CircleCi, the request to start the teardown workflow fails with "branch not found" error.
The question now is, how can I make circleCi retain the branch that was deleted on Github so that this request will run? I can make the teardown job then delete the branch from CircleCi after the teardown is done.
The request to CircleCi to start the teardown workflow looks like this...
curl -X POST 'https://circleci.com/api/v2/project/github/<organization>/<project_name>/pipeline' \
-H 'Circle-Token: ${{env.CIRCLECI_TOKEN}}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d "{\"branch\":\"${{env.CIRCLECI_BRANCH}}\",\"parameters\":{\"pull_request_closed\":true}}"
I think the actual issue here is this:
This syntax to reference a CircleCI environment variable is incorrect.
Try this instead:
Also, this statement:
is not completely true.
Although the related branch might be deleted from the "Filter Branches" list, any build that ran on the now-deleted branch will still be present and visible in CircleCI.
You can access them either by: