Skip to content

Commit

Permalink
Merge pull request #14 from artplan1/webhook-enpoint-env [Semver:Minor]
Browse files Browse the repository at this point in the history
Use webhook enpoint value from ENV
  • Loading branch information
KyleTryon authored Oct 9, 2019
2 parents 58cd08c + 958ac54 commit b7db623
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ See the [orb registry listing](http://circleci.com/orbs/registry/orb/circleci/sp

- Some of the commands require a Linux environment to execute in. Refer to the [orb registry listing](http://circleci.com/orbs/registry/orb/circleci/spinnaker) for the descriptions of each command.

- `SPINNAKER_WEBHOOK` environment variable should be set in CircleCI project settings

## Examples

Full usage examples can be found on the Spinnaker orb's page in the orb registry, [here](https://circleci.com/orbs/registry/orb/circleci/spinnaker#usage-examples).
Expand Down Expand Up @@ -57,7 +59,6 @@ jobs:
# Send a request to a webhook endpoint pre-configured in Spinnaker
# Ref: https://www.spinnaker.io/guides/user/pipeline/triggers/webhooks/
- spinnaker/trigger-pipeline-with-webhook:
webhook-endpoint: "http://localhost:8084/webhooks/webhook/myappwebhook"
payload: "{\\\"status\\\": \\\"success\\\", \\\"jobid\\\": \\\"$CIRCLE_WORKFLOW_JOB_ID\\\", \\\"message\\\": \\\"I've got it\\\"}"
workflows:
example-workflow:
Expand Down
16 changes: 12 additions & 4 deletions src/commands/trigger-pipeline-with-webhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ description: |
parameters:
webhook-endpoint:
description: |
Webhook endpoint
type: string
Name of environment variable defined in CircleCI
containing the webhook endpoint URL pre-configured in Spinnaker
Example of value: http://localhost:8084/webhooks/webhook/myappwebhook
type: env_var_name
default: SPINNAKER_WEBHOOK
payload:
description: |
JSON payload. Escaping of double quotes in the payload is required;
Expand All @@ -22,5 +25,10 @@ steps:
- run:
name: Trigger Spinnaker pipeline with webhook
command: |
WEBHOOK_ENDPOINT="<< parameters.webhook-endpoint >>"
curl -X POST -H "content-type: application/json" -d "<< parameters.payload >>" ${WEBHOOK_ENDPOINT}
if [ -z "<< parameters.webhook-endpoint >>" ]; then
echo "No webhook endpoint url set"
echo "Please input your SPINNAKER_WEBHOOK value in the CircleCI settings for this project or as a parameter for this orb."
exit 1
else
curl -X POST -H "content-type: application/json" -d "<< parameters.payload >>" ${<< parameters.webhook-endpoint >>}
fi

0 comments on commit b7db623

Please sign in to comment.