Rocket.Chat SaaS
TravisCI
Add TravisCI notifications via a new WebHook in Rocket.Chat

Receive alerts

  1. 1.
    Create a new Incoming WebHook.
  2. 2.
    Select the channel where you will receive the alerts. You may wish to create a dedicated channel for your notifications.
  3. 3.
    Select an account from which the alerts will be posted. You may wish to create a dedicated account just for notifications.
  4. 4.
    Set the "Enable Scripts" option to True.
  5. 5.
    Copy scripts below and paste it in Script field.
  6. 6.
    Save the integration. This will generate a webhook URL and secret for you.
  7. 7.
    In your .travis.yml file add WebHooks parameter with webhook URL generated.
1
notifications:
2
webhooks: <webhook_url_generated>
Copied!
This script will generate notifications for the following build events:
  • Build finished status for any pushed code
  • Build finished status for new Pull Request
Screenshot of messages generated by TravisCI integration script
Note: If status is passed, message color is green otherwise it is red.
1
const buildMessage = (obj) => {
2
const min = Math.floor(obj.duration / 60);
3
const sec = obj.duration - min * 60;
4
5
let template = `Build [#${obj.number}](${obj.build_url})`;
6
template += ` ([${obj.commit.substring(0, 7)}](${obj.compare_url})) of`
7
template += ` ${obj.repository.owner_name}/${obj.repository.name}@${obj.branch}`;
8
if(obj.pull_request) {
9
let pr_url = `https://github.com/${obj.repository.owner_name}/`;
10
pr_url += `${obj.repository.name}/pull/${obj.pull_request_number}`;
11
template += ` in PR [#${obj.pull_request_number}](${pr_url})`;
12
}
13
template += ` by ${obj.author_name} ${obj.state} in ${min} min ${sec} sec`;
14
15
let status_color = '#36A64F';
16
if(obj.state !== 'passed') {
17
status_color = '#A63636'
18
}
19
20
return {
21
text: template,
22
color: status_color
23
};
24
};
25
26
class Script {
27
process_incoming_request({ request }) {
28
msg = buildMessage(request.content);
29
30
return {
31
content:{
32
attachments: [
33
{
34
text: msg.text,
35
color: msg.color
36
}
37
]
38
}
39
};
40
}
41
}
Copied!
If you want more customizations, please look in TravisCI documentation: https://docs.travis-ci.com/user/notifications/#Configuring-webhook-notifications
Export as PDF
Copy link