tag:help.appveyor.com,2012-11-13:/discussions/questions/10376-only-send-a-notification-based-on-some-conditionAppVeyor: Discussion 2018-10-19T08:18:31Ztag:help.appveyor.com,2012-11-13:Comment/437015212017-10-09T15:36:06Z2017-10-09T15:36:06ZOnly send a notification based on some condition.<div><p>We do not have a built-in feature to send notification on some specific conditions other than build success, failure or status change. So yes PowerShell sending Slack notification is a way to go. Slack API is very clean an straightforward, so it should not be a problem. Please look at <a href="https://gist.github.com/IlyaFinkelshteyn/0796f738317dcb47ba62719d69e05c2c">this sample</a>, but sure token should be a <a href="https://www.appveyor.com/docs/build-configuration/#secure-variables">secure variable</a> in your case. Good place to call this script in <a href="https://www.appveyor.com/docs/build-configuration/#build-pipeline">build pipeline</a> is <code>after_deploy</code> step.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/437015212018-05-23T11:12:26Z2018-05-23T11:12:27ZOnly send a notification based on some condition.<div><p>Hi,</p>
<p>just found this discussion as I'm facing a similar challenge. However, my goal is to comment on GitHub issues conditionally via the GitHubPullRequest notification provider. The emphasis is on conditionally, i.e., not for all successful builds.</p>
<p>Is this possible anyhow?</p>
<p>Thanks!</p></div>Akos Kisstag:help.appveyor.com,2012-11-13:Comment/437015212018-05-23T17:28:06Z2018-05-23T17:28:08ZOnly send a notification based on some condition.<div><p>Hi,</p>
<p>I've been typing my above comment hastily and made an error: my goal is to comment conditionally on GitHub <em>pull requests</em>, of course.</p>
<p>BTW, I've also found this discussion: <a href="https://help.appveyor.com/discussions/problems/7420-notifications-only-send-with-an-on-condition">https://help.appveyor.com/discussions/problems/7420-notifications-o...</a> . A generic <code>on:</code>-based approach would be great, e.g., one that could check the value of an environment variable as shown in the deployment part of the reference yml at <a href="https://www.appveyor.com/docs/appveyor-yml/">https://www.appveyor.com/docs/appveyor-yml/</a>:</p>
<pre>
<code> - provider: Environment
name: staging
on:
branch: staging
env_var1: value1
env_var2: value2</code>
</pre>
<p>But for notifications, of course. Something like:</p>
<pre>
<code>notifications:
- provider: GitHubPullRequest
on_build_success: true
on:
my_env_var: 1
# assuming that I've managed to set an env var during the build
# e.g., using the build worker API</code>
</pre>
<p>So, what do you think, is this too far-fetched of an idea?</p></div>Akos Kisstag:help.appveyor.com,2012-11-13:Comment/437015212018-05-23T23:10:14Z2018-05-23T23:10:14ZOnly send a notification based on some condition.<div><p>There is a fundamental issue with this approach. Notifications are (at least now) build-level setting. However the same environment variable can have different value across different jobs inside the same build. Not sure which one is supposed to be trusted.</p>
<p>Regarding <a href="https://www.appveyor.com/docs/notifications/#github-pull-request">GitHub Pull Request</a> it does not fire on builds that are result of <code>push</code>, only in PRs. Or you need more granular control?</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/437015212018-05-23T23:38:21Z2018-05-23T23:38:22ZOnly send a notification based on some condition.<div><p>Yes, it would be great to have more granularity in some sense. Let me outline the envisioned use case: there are some "regular" build jobs that are always executed and there is one job that is conditionally executed: it checks whether an opt-in string is present in the commit message early in the init phase and exits (either with success or with failure, it's irrelevant for now) if it's not there. But if it's there, it compiles some info via the build worker API into the job's messages and these messages get commented to the PR using the GitHubPullRequest notification provider.</p>
<p>The why: Obviously, it would be an easier option not to go for an opt-in approach and always run the message-creating job but that would generate too many comments on a PR that gets updated multiple times (e.g., because of multiple review rounds). That would annoy developers, which would lead to the disabling of the whole notifications thing.</p>
<p>The problem: Right now, I can only disable the "extra" job but not the sending of the notifications. So, even if the messages are not generated, an empty comment gets posted anyway.</p>
<p>Here is a version of the yml configuration: <a href="https://github.com/akosthekiss/jerryscript/blob/a2ed6849e3514167c2bc4439051dfbc5bdb17180/appveyor.yml">https://github.com/akosthekiss/jerryscript/blob/a2ed6849e3514167c2b...</a></p>
<p>And here is the concept tested: <a href="https://github.com/jerryscript-project/jerryscript/pull/2353">https://github.com/jerryscript-project/jerryscript/pull/2353</a></p></div>Akos Kisstag:help.appveyor.com,2012-11-13:Comment/437015212018-05-24T09:49:34Z2018-05-24T09:49:36ZOnly send a notification based on some condition.<div><p>Well, there seems to be a workaround but it's not the nicest one. It turned out that during previous variants of the configuration the message was only visually empty, it contained <a><sup>\n\n\n\n</sup>". With some reorganization of the template I could really make the message an empty string, which caused GH to reject the comment. The job now has an extra log entry stating that (https://ci.appveyor.com/project/jerryscript-project/jerryscript/build/1.0.9-tpowpobc/job/7wgmu427h1ut0nca):</a></p>
<p><a>Error sending GitHubPullRequest notification: Error commenting on GitHub pull request: {"message":"Validation Failed","errors":[{"resource":"IssueComment","code":"custom","field":"body","message":"body cannot be blank"}],"documentation_url</a></p>
<p>Effectively, this makes the notification conditional so it works for now but it's a bit of an abuse of the GH API. It might be more polite to check for empty messages and do the rejection of the notification on AV side.</p></div>Akos Kisstag:help.appveyor.com,2012-11-13:Comment/437015212018-05-24T17:37:08Z2018-05-24T17:37:42ZOnly send a notification based on some condition.<div><p>Nice hack :) Actually we had a discussion yesterday regarding more general plans to implement better coordination/chaining between jobs. And as part of this plan we realized that we have to implement job-level notifications. No ETA yet, but this is what we plan to work on it this year.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/437015212018-05-24T22:22:28Z2018-05-24T22:22:30ZOnly send a notification based on some condition.<div><p>Great, looking forward to announcements.</p></div>Akos Kiss