tag:help.appveyor.com,2012-11-13:/discussions/questions/35656-how-can-i-trigger-a-notification-only-when-a-branch-is-mergedAppVeyor: Discussion 2019-03-19T16:59:11Ztag:help.appveyor.com,2012-11-13:Comment/470833712019-03-18T07:50:02Z2019-03-18T07:50:04ZHow can I trigger a notification only when a branch is merged?<div><p>I have a notification configured only to fire for a certain branch, however it seems that pull requests against that branch also trigger the notification. Is it possible to only send the notification when the pull request is merged?</p>
<p>Config Excerpt:</p>
<h2><a name="-pre-code-" class="anchor" href="#-pre-code-"></a></h2>
<pre>
<code>
<br>branches:
only:
- development<br><br>
<br>notifications:
- provider: Slack
incoming_webhook: https://hooks.slack.com/services/xxxxxxxxxxx
on_build_success: true
on_build_failure: false
template: >-
{{#jobs}}
{{#artifacts}}
<{{url}}|Build {{buildVersion}}>
{{/artifacts}}
{{/jobs}}<br><br>
</code>
</pre>
<pre>
<code><code> &lt;{{buildUrl}}|Appveyor&gt; &lt;{{commitUrl}}|Github&gt;</code></code></code>
</pre>
<pre>
<br>
</pre></div>burke livingstontag:help.appveyor.com,2012-11-13:Comment/470833712019-03-18T19:27:15Z2019-03-18T19:27:15ZHow can I trigger a notification only when a branch is merged?<div><p>Hi Burke,</p>
<p>We have no option to filter notification by PR. But what you can do is instead of built-in notification write a simple script based on slack REST API (<a href="https://gist.github.com/IlyaFinkelshteyn/0796f738317dcb47ba62719d69e05c2c">sample</a>) and run it only if <code>APPVEYOR_PULL_REQUEST_TITLE</code> environment variable is not set <code>AND</code> <code>APPVEYOR_REPO_BRANCH</code> is <code>development</code>. Run it <code>on_finish</code></p>
<p>Something like this:</p>
<pre>
<code>on_finish:
- ps: if ((-not $env:APPVEYOR_PULL_REQUEST_TITLE) -and ($env:APPVEYOR_REPO_BRANCH -eq "development")) {.\notifySlack.ps1}</code>
</pre>
<p>For Slack notification script you can also use <a href="https://www.appveyor.com/docs/environment-variables/">environment variables</a>. And sure use <a href="https://www.appveyor.com/docs/build-configuration/#secure-variables">secure variable</a> for Slack token.</p>
<p>Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/470833712019-03-19T07:14:21Z2019-03-19T07:14:25ZHow can I trigger a notification only when a branch is merged?<div><p>Hi Ilya,<br>
This was very helpful. Thank you for your quick reply.</p>
<ul>
<li>Burke</li>
</ul></div>burke livingston