Skip to content

Commit

Permalink
feat: End maintenance window in all cases (#2)
Browse files Browse the repository at this point in the history
* feat: End maintenance window in all cases

* docs: Update description for delete-maintenance-window command

* fix: Fix orb syntax for run
  • Loading branch information
Timo Reymann committed Mar 23, 2022
1 parent 3ab4bd1 commit cdc6010
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/commands/delete-maintenance-window.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: >
Delete maintenance window
Delete maintenance window. The delete step will always be executed, even if parts of your pipelines fail.
parameters:
maintenance-window-id:
Expand All @@ -18,3 +18,4 @@ steps:
PARAM_MAINTENANCE_WINDOW_ID: <<parameters.maintenance-window-id>>
PARAM_PAGERDUTY_TOKEN: <<parameters.pagerduty-token>>
command: <<include(scripts/maintenance-window-delete.sh)>>
when: always
16 changes: 11 additions & 5 deletions src/scripts/maintenance-window-delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ fi
pagerduty_token=$(eval echo "\$$PARAM_PAGERDUTY_TOKEN")
PARAM_MAINTENANCE_WINDOW_ID=$(eval echo "\$$PARAM_MAINTENANCE_WINDOW_ID")

curl --request DELETE \
--url "https://api.pagerduty.com/maintenance_windows/${PARAM_MAINTENANCE_WINDOW_ID}" \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header "Authorization: Token token=${pagerduty_token}" \
--header 'Content-Type: application/json' | jq
if [ -z "${PARAM_MAINTENANCE_WINDOW_ID}" ]
then
echo "WARNING: Maintenance window does not exist. Ignoring, if the maintenance window creation did not fail, make sure to check your pipeline is built as expected!"
else
echo "Maintenance window found, ending it."
curl --request DELETE \
--url "https://api.pagerduty.com/maintenance_windows/${PARAM_MAINTENANCE_WINDOW_ID}" \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header "Authorization: Token token=${pagerduty_token}" \
--header 'Content-Type: application/json' | jq
fi

0 comments on commit cdc6010

Please sign in to comment.