Netlify

Do you want to be notified when a Netlify deployment completes, or do you want to trigger a deployment manually?

Deployment notification

Netlify offers a handy functionality, called outgoing webhooks  , which lets you receive a webhook whenever certain conditions are met, e.g. whenever a build was successful or when it failed.

Because Notify17’s main focus is on handling webhooks, it is very easy to connect these two systems together:

  1. Create a template to support the webhook.
  2. Create the webhook.
  3. (Optional) Use an action to deploy your build.

1. The template

To get started with Netlify’s webhooks, import and save the following template:

Template
Netlify - {{.name}}/{{.state}} in {{.deploy_time}}s

---

State: {{ .state }} 

URL: {{ .ssl_url }}
{{- if .commit_url }}
Commit URL: {{ .commit_url }}
{{- end }}
{{- if .deploy_time }}
Completed in {{ .deploy_time }}s
{{- end }}

Title: {{ .title }}

{{- if .published_at }}
Published at: {{ .published_at }}
{{- end }}

{{ if .error_message }}Error: {{ .error_message }}{{ end }}

{{ range $message := .summary.messages -}}
* {{ $message.title }}: {{ $message.description }}
{{- if existsAndNE $message.details "" }}
{{ $message.details | Indent 2 }}
{{- end }}
{{ end }}

{{- if .screenshot_url }}
Screenshot: {{ .screenshot_url }}
{{- end }}

Admin URL: {{ .admin_url }}
Rendered
Netlify - example123/ready in 9s

---

State: ready 

URL: https://example123.net
Commit URL: https://github.com/moo/cow/commit/71c2ad145e923f306a019580bec29c11f2d011a1
Completed in 9s

Title: my commit!

* 7 new files uploaded: 7 generated pages changed: All files already uploaded.
* 1 redirect rule processed: All redirect rules deployed without errors.

Admin URL: https://app.netlify.com/sites/example123
Payload (JSON)
{
  "admin_url": "https://app.netlify.com/sites/example123",
  "commit_url": "https://github.com/moo/cow/commit/71c2ad145e923f306a019580bec29c11f2d011a1",
  "deploy_time": 9,
  "name": "example123",
  "screenshot_url": null,
  "state": "ready",
  "ssl_url": "https://example123.net",
  "title": "my commit!",
  "summary": {
    "messages": [
      {
        "description": "All files already uploaded.",
        "title": "7 new files uploaded: 7 generated pages changed",
        "...": "..."
      },
      {
        "description": "All redirect rules deployed without errors.",
        "title": "1 redirect rule processed",
        "...": "..."
      }
    ]
  },
  "...": "..."
}

2. How to set up a new webhook?

You can find more reference about webhooks in Netlify’s docs  .

  1. Navigate to Netlify’s dashboard 


  2. Open the Domain Settings page of your website

  3. Navigate to the Build & deploy -> Deploy notifications section

  4. Create a new Outgoing webhook

  5. Setup the webhook:

    1. Choose the event you want to be notified about, e.g. Deploy succeeded
    2. In the URL to notify field, copy/paste your notification template URL
    3. Click on Save

That’s it, you will not be notified whenever e.g. a build will be successfully completed!

3. Deploy your build using an action

There may be cases where you don’t want Netlify to automatically deploy a build, e.g. you have production builds which need to be tested beforehand using a different URL.

In these cases, you are probably using locked deploys  , which force you to manually click on a Publish button when you want to deploy a specific build.

You can easily delegate this business to a Notify17 notification action: whenever a build completes, you will receive a notification (e.g. set up in the previous sections of this recipe), and this notification will contain a Deploy button, which you can use to deploy the build.

To set this action up:

  1. Generate a personal access token, by navigating to Netlify’s user settings  .

    1. Click on New access token
    2. Enter a meaningful description, e.g. Notify17, and click on Generate token
    3. Copy your token, and use it in the next step!
  2. Import the following action template, and replace REPLACE_API_TOKEN with the personal access token you just generated in the previous step.

Example
label: Deploy
action: httpRequest
args:
  body: ""
  bodyIsYAMLToJSON: true
  doNotFollowRedirects: false
  headers: |-
    Content-Type: application/json
    Authorization: Bearer REPLACE_API_TOKEN    
  method: POST
  query: ""
  successCondition: and (ge .statusCode 200) (le .statusCode 299)
  url: https://api.netlify.com/api/v1//sites/{{ .site_id }}/deploys/{{ .id }}/restore

# We want to show this action only if the build has succeeded
createCondition: eq .state "ready"
  1. Save the notification template.

That’s it! Whenever a build will succeed, you will be notified about it, and you will be able to use the handy Deploy button.