I’m setting up a webhook for CircleCI to talk to at the end of every build, but I want to not expose my authentication token to Github. I’ve tried setting an environment through the CircleCI web UI but it doesn’t seem to be working. At first I tried something like “-url: https://www.example.com/endpoint?token=<%= API_TOKEN =>” and that gave me an uncaught exception, I then tried “-url: https://www.example.com/endpoint?token=$API_TOKEN” but that returns a 401 (most likely because API_TOKEN is empty and authentication fails). I have also tried {API_TOKEN} with the same result. What is the correct way to call an environment variable inside the ‘circle.yml’ file, and is setting an environment variable through the Circle CI web UI the correct way to do this?
I would like to be able to have my circle yaml look something like machine: environment: APP_PATH: "testing" notify: webhooks: - url: "https://example.com?appPath=$APP_PATH"
just as good engineering practice, for variable re-use and what not.
This greatly diminishes the usefulness of the webhooks, as there’s no way to verify the payload (since it’s impossible to add a secret token as a URL parameter). No secret token means that the web hook can’t trust any of the data received in the payload, as there’s no way to verify that the request actually came from CircleCI. This means the payload is essentially useless and any webhook is going to have to hit CircleCI’s build API to get the data.
Webhooks are still useful, but they must always ignore the payload other than the build number, especially in open-source projects where the circle.yml file is publicly accessible
I also would like environment variables in webhooks but an alternative way to verify that the request came from CircleCI is to do a GET request and see if the build payload matches up (because webhook notify’s payload should be identical to the Build API)
an alternative way to verify that the request came from CircleCI is to do a GET request and see if the build payload matches up
That’s what I ended up doing - I only use the build number from the payload and ignore everything else. I do a GET to their API and then treat that data as the source of truth. It’s annoying to do that though, and it’d be unnecessary if CircleCI just included some sort of private token in the payload.
+1 for having environment variables. I did try to solve a problem with notifications (Formatted Slack message after successful build) through a webhook, just to realise this will not provide me the $BRANCH_NAME variable.
First step is to make sure we have this as a proper feature request. Does this one make sense? If you, " 'ing" the top post will help gauge interest in it.
I do agree that webhooks should have environment variable support. That’s just common sense to me.
I’m also looking for a way to get this support. I’d previously been using the webhook element but want to avoid inlining the API key.
I’ve tried using the notification tag with a command element:
notify:
# The default webhook integration doesn't expand environment variables in the webhook url definition.
# We workaround this by querying the build info via. the REST API then packaging this result as a notification
# payload and pushing to OpsGenie. See https://circleci.com/docs/1.0/configuration/#notify for documentation.
command: |
BUILD_INFO=$(curl https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$CIRCLE_BUILD_NUM?circle-token=$CIRCLE_LOCK_API_TOKEN)
curl -d "{\"payload\": $BUILD_INFO}" -H "Content-Type: application/json" -X POST https://api.opsgenie.com/v1/json/circleci?apiKey=$OPS_GENIE_API_KEY
I’ve manually SSH’d into the Circle pod for the build and the commands work fine when run directly. However they don’t appear to be called when run as part of the regular build file. i.e. CI seems to ignore the command sub-element. Am I missing something or is this WAI?
The inability to parse an environment variable in the notify section is disappointing - my project(s) are all open source but my team’s private chat room is not; I really don’t want to post our chat room’s API token into the config.yml file. An env var would be the perfect way to obscure it!
I absolutely agree with everyone here, not having the option of using environment variables inside the config makes using CircleCI pretty difficult right now. What is even more frustrating is your lack of communication regarding this. There are several threads where people discuss this issue only to receive a one-line answer that doesn’t solve anything.