You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
5.0 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. # Matrix Notification Resource for Concourse CI
  2. Send notification messages to [Matrix](http://matrix.org) using a string message or templated message.
  3. This resource borrows heavily from the [Slack notification resource](https://github.com/cloudfoundry-community/slack-notification-resource). Usage and behavior around text and text_file parameters should be handled exactly the same as in that.
  4. ## Installing
  5. ```
  6. resource-types:
  7. - name: matrix-notification-resource
  8. type: docker-image
  9. source:
  10. repository: freelock/matrix-notification-resource
  11. ```
  12. ## Registering with Matrix
  13. This resource needs an access token for a valid user account. It will not create the user account for you, or retrieve the token.
  14. To get a token, first create a Matrix user account on your homeserver of choice. Then you can use Curl to get an access token for the account:
  15. ```
  16. curl -XPOST -d '{"type":"m.login.password", "user":"example", "password":"wordpass"}' "http://matrix.org/_matrix/client/api/r0/login"
  17. {
  18. "access_token": "QGV4YW1wbGU6bG9jYWxob3N0.vRDLTgxefmKWQEtgGd",
  19. "home_server": "matrix.org",
  20. "user_id": "@example:matrix.org"
  21. }
  22. ```
  23. ... add the returned access_token to the resource.
  24. Then, a user will need to invite the account to the appropriate room, and the account will need to accept the invitation.
  25. ## Source Configuration
  26. * `matrix_server_url`: *Required.* Example: https://matrix.org
  27. * `token`: *Required.* token to authenticate with Matrix server
  28. * `room_id`: *Required.* The room to send notifications to -- this account must already be a member of this room.
  29. * `msgtype`: Used to post a custom message type e.g. if you want to attach a json blob. If set to anything other than m.notice, the resource will attach a "build" json object containing the build metadata info. Defaults to `m.notice`, can be overridden by the put resource.
  30. * `data_file`: *Optional.* (string) Default file to post to the data key of a custom message type. The contents of this file is generally assumed to be a JSON-encoded string. Can be overridden in the job parameters.
  31. Pull requests accepted for room_alias, user logins, auto-joins.
  32. #### `out`: Sends message to Matrix room
  33. Send message to specified Matrix Room, with the configured parameters
  34. #### Parameters
  35. * `text`: (string) Text to send to the Matrix room as the content.body.
  36. * `text_file`: (string) File containing text to send to the Matrix room as the content.body.
  37. * `msgtype`: *Optional.* Message type, m.notice, m.text (default: m.notice)
  38. * `is_html`: *Optional.* Indicate that the input is formatted as html
  39. * `data_file`: *Optional.* (string) Filename to post using a custom_event message type. If unset, defaults to the data_file on the resource. If it exists, the file must contain valid JSON.
  40. * `trigger`: *Optional.* (string) Arbitrary test to add to a "trigger" data item on custom message types.
  41. * `always_notify`: If true, send a notice even if text_file and data_file are empty. If false, and a text_file is specified but empty, a notification will not be sent.
  42. * `prefix`: If set, this will be added to the beginning of a message. Commonly used with $BUILD_PIPELINE_NAME to indicate which pipeline is sending this message.
  43. * `link`: If set to true, will wrap the text in a link to the build using the pattern $ATC_EXTERNAL_URL/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME
  44. ## Example
  45. ### Resources
  46. ```
  47. ---
  48. resources:
  49. - name: matrix-notification
  50. type: matrix-notification-resource
  51. source:
  52. matrix_server_url: https://matrix.org
  53. token: {{matrix_token}}
  54. room_id: {{matrix_room_id}}
  55. msgtype: com.freelock.data
  56. data_file: data
  57. ```
  58. ### Check
  59. *Not supported*
  60. ### In
  61. *Not supported*
  62. ### Out
  63. ```
  64. ---
  65. ---
  66. - put: matrix-notification
  67. params:
  68. text_file: results/message.txt
  69. text: |
  70. The build had a result. Check it out at:
  71. http://my.concourse.url/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME
  72. or at:
  73. http://my.concourse.url/builds/$BUILD_ID
  74. Result: $TEXT_FILE_CONTENT
  75. ```
  76. Matrix has the ability to attach and store arbitrary JSON. This can be very useful to send arbitrary results that a bot might use for further action. Freelock uses this ability to pass extensive information about various deployment environment settings, while keeping the human-readable portion brief.
  77. These extra data keys are not sent if using the default `m.notice` message type, but if you define a custom msgtype, this resource will automatically add a JSON object containing the build data -- Job name, pipeline name, build name (the sequence number within this pipeline), build id, and concourse ATC url. It will also attach the contents of a data file added to the `data` key, and a `trigger` key that is useful to easily pass info about a particular Matrix put -- e.g. 'success', 'fail', 'start', 'end', 'info' -- which your Matrix bot might find useful for handling the message.
  78. ```
  79. - put: matrix-notification
  80. params:
  81. msgtype: com.freelock.data
  82. data_file: matrix-notification/data
  83. trigger: fail
  84. message: Test failure.
  85. ```