Manual CLI deploy - Slack notification contains prod URL instead of branch preview URL

I’m manually deploying merge request pushes as branch previews using netlify-cli:

netlify deploy --auth $NETLIFY_AUTH_TOKEN --site $NETLIFY_SITE_ID_NATTT

This works nice and because I’m not using the --prod flag, a deploy preview is created as expected. I have Slack notifications configured like this:

Message Slack #my-channel when deploy succeeds

As soon as the deployment finishes, I get a notification indeed:


While the “check build log” link points to the correct build log for my cli-triggered build, the “Visit the changes live” link points to the production environment instead of the branch preview.

Is there any way to fix that? I noticed that cli builds no longer appear in the Netlify UI and therefore notifications like “Comment on pull request” don’t work at all. Is my issue related to that fact?

If I can’t fix that with simple configuration, is it possible to retrieve the deploy preview URL in a CI pipeline so that I can send my own Slack notification instead?

Hey @Shackles,

Could you clarify what you mean by that? All deploys should be visible in the UI, no matter from where they’re made.

About fixing, I’ve not tried Slack notifications myself and don’t have the bandwidth to set that up right now, but I believe you can use a custom Netlify Function which you can trigger on build and post to Slack from that. I believe you can use $DEPLOY_URL environment variable to achieve that.

I mean that when I manually deploy using the CLI, the deployments do not appear in the Netlify UI as “Production Deploys” or “Deploy Preview” (s. screenshot). I had several successful deployments since the last ones displayed in the UI but they don’t show up if you pause builds.

I worked around the issue by manually sending Slack Notifications for now but it would be so much easier if Netlify would evaluate whether the “–prod” flag was set or not for the last deployment and would then return either the production env or the deploy preview as link in the Slack notification.

You can test this easily:

  • Create a new site on Netlify & connect it to git
  • configure Slack notifications for the new site on deploy succeeded
  • disable builds on the Netlify site
  • use netlify-cli to link the site
  • manually deploy using netlify-cli
    • without the --prod flag
      with the --prod flag

Both notifications will point to the same Test URL which is the prod environment URL. Build logs are linked correctly, so the one without --prod takes you to the Deploy Preview build log that also contains the correct Deploy Preview URL that I’d like to see in the Slack notification.

Thanks for the report and all the details!

We have an open bug filed on this behavior, to which I’ve added your voice. I do not think that we are likely to fix it soon, so if it is incredibly important to you for your slack notification to look correct, read on for some suggestions to work around this.

You could forward it via a service like that can parse the webhook body, and then relay the message you want to slack that which you care about more (or you could use a different notification service like email; I believe the link there is correct).

Regardless, the webhook notification body does contain the detail you want - the permalink for that specific deploy - so the data you crave is there, slack just doesn’t show it today with the way we notify.

There are also a lot of other ways to work around this shortcoming, but they’ll probably take more effort, for instance:

  • using a deploy-succeeded event-triggered function (which will get all the details about your build, and can do anything you can code)
  • using our API to poll the site for new deploys; the API call that identifies the current production deploy will change once you’ve deployed (or you can list all deploys and filter for non-production deploys).

Okay, thanks for your reply and the proposed workarounds! I am currently grep’ing the URL from the console output returned by the manual netlify-cli deployment and then I send my own notification from my CI/CD pipeline but I agree that using a Netlify function would make more sense.

1 Like

great. let us know if you need more help with this!