Get Slack webhook when pages build finished / Cloudflare Pages

It will be good to get Slack messages when build was finished.
Or, is there any events to implement this with Cloudflare Workers?

Webhooks are on the roadmap! It is something I am strongly pushing for myself.

There is currently no good way to do this but you could setup a GitHub Action or Worker to keep polling the status and then send a Slack message. Not good but, it works.

2 Likes

Hi @WalshyMVP -

Any idea on an ETA for when webhooks / notifications will be available for Cloudflare Pages? We’re starting to grapple with organizational security around this, while trying to allowing contractors to view build status, etc. Thanks in advance!

No ETA, Cloudflare doesn’t do ETAs haha. Hopefully soon but who knows

+1 for this feature. I’m using Netlify for a small number of my projects only for this feature, and would be using Cloudflare Pages for those if I could POST to a webhook after the build completes.

I found a partial solution, and will be working on it further.

For now, I was able to run the following build command for my Nuxt app in Cloudflare Pages:
yarn generate && curl -X POST -H 'Content-type: application/json' --data '{"text":"ApplicationName Deployed"}' https://example.com/webhook-endpoint

My example.com is a Slack webhook endpoint, so I’m getting notified in a Slack Channel via a custom Slack App whenever the build completes.

I suppose I can work the build command into the package.json file, changing scripts.generate from nuxt generate, appending it with the curl command.

This is almost exactly what I need, except the slight issue where it’s technically sending this command prior to deployment. For my purposes, it’s working great.

1 Like

We need webhooks at least post-deploy - so +1

1 Like

If Cloudflare is serious about Pages being a reasonable product offering for regular webpages, you’ll need some way for people to delegate limited access to a webdev. Today, it’s easy to set them up with granular access through github to make changes in a branch, but they can’t see the resulting nonprod builds (randomstring.url.pages.dev) without full admin access to the Cloudflare console. Even Cloudflare posting resulting build results + urls back to github would work pretty well.

1 Like

strongly +1 with dylan.n.evans.
It might be a simple feature, but it is necessary for us.

The information that build environments gave is not useful to make webhooks(or alerts).
It is hard to get data such as deploy ID, canonical URL, and so on.
(afaik, polling results with GitHub Actions or Worker are available if we know each deploy ID of deployments :thinking: )

I think Cloudflare Pages rather give metadata in the build environments like Netlify, if there are no plan to make and release this feature in the near future. Then we might build it for our own.

also a bit worried that lack of these kind of features make people not to choose Cloudflare Pages, even it has a strong advantages :frowning:

cc: @WalshyMVP

Either I’m not observant or or Cloudflare dev team is super fast. I just noticed this morning that my nonprod build environment is persistent, which solves this problem for me.

preview.[url].pages.dev

you can see my example live at preview.saltyonsecurity.pages.dev

it’s not fancy enough to have multiple builds from multiple branches, but honestly, if you have more than a couple devs pushing changes and they want their own branches, you should probably just invest in your own PaaS infra to match the environment you want (maybe locally hosted docker, etc).

Now that builds are 15-ish seconds and don’t have a long lead-time, this works great - I don’t even need notifications in slack - I just hit refresh.

Hi there,
I know this is an old thread but wanted to share with you this.
If you are using GitHub action you can use GitHub - arddluma/cloudflare-pages-slack-notification: CloudFlare Pages Slack notifications which I have published lately (Slack integration was the only thing that were missing in CF Pages).
It is based on @WalshyMVP - CF Pages Await action (GitHub - WalshyDev/cf-pages-await: Wait for your Cloudflare Pages builds to finish!)
Here is an example:

name: Deploy
on: 
  push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
    - name: Await CF Pages send slack messages
      uses: arddluma/[email protected]
      with:
        accountEmail: ${{ secrets.CF_ACCOUNT_EMAIL  }}
        apiKey: ${{ secrets.CF_API_KEY  }}
        accountId: ${{ secrets.CF_ACC_ID  }}
        project: ${{ secrets.CF_PROJECT  }}
        githubToken: ${{ secrets.GITHUB_TOKEN }}
        slackWebHook: ${{ secrets.SLACK_WEBHOOK  }}

Hope it helps!

Just to unpack the above comment - that GitHub action is quite straightforward. It polls the CF API that lists out all the deployments and then greps for the commit hash. If it exists, then deploy was done. The entire curl call with the CF endpoint looks like this:

curl --location --request GET \
https://api.cloudflare.com/client/v4/accounts/{account_id}/pages/projects/{project_name}/deployments?sort_by=created_on&sort_order=desc'\
 --header 'X-Auth-Email: {email}'\
 --header "Authorization: Bearer {token}"

For this, I needed to create an API token with Cloudflare Pages read access and that was basically it. My plan is to essentially fire this off at the very end of my build which goes into an AWS Lambda function that keeps polling until it finds the Git commit hash. From my observations, the time it takes from build completion to deployment is no more than 8 seconds, so I should not have to poll too many times.