A Jenkins plugin to interact with jobs and builds, with slash commands in Mattermost.
Originally developed by Wasim Thabraze.
By extending Mattermost with the Jenkins integration, your team will enjoy:
- Improved collaboration. Keep your team in sync with your latest build by automatically routing notifications to specific Mattermost Channels to display information about when builds start, whether they’re successful, or if exceptions occurred.
- Increased productivity. Start Jenkins job builds and get logs and artifacts—all without leaving the Mattermost platform.
- Centralized workflows. Consolidate builds into one channel to keep a timeline of key Jenkins builds in one place and avoid hunting across builds.
Integrating Mattermost with Jenkins lets you keep your whole DevOps team on top of recent builds and any failures that may occur. With the Mattermost Jenkins plugin, control over Jenkins functions is always at the fingertips of your entire DevOps team.
By using the Mattermost Jenkins integration, your team will spend less time switching over to Jenkins, logging in, and finishing builds.
For a Jenkins integration that sends webhook notifications from Jenkins to Mattermost as post-build actions, see this repository: https://github.com/jenkinsci/mattermost-plugin This is useful for sending Jenkins notifications to specific channels. For example - whenever a new Release of your software is cut, it should notify the #Release channel in Mattermost. Using the Jenkins post-build action plugin lets you notify the right channels about success/failures.
This plugin enables you to interact with jobs via slash commands in Mattermost. The supported slash commands are listed below:
- Connect to Jenkins server -
/jenkins connect username APIToken
- Connect your Mattermost account to Jenkins. - Disconnect from Jenkins server -
/jenkins disconnect
- Disconnect your Mattermost account from Jenkins.
-
Create a Jenkins job -
/jenkins createjob
- Create a Jenkins job using contents ofconfig.xml
. The slash command opens an interactive dialog for the user to input the job name and paste the contents ofconfig.xml
. -
Trigger a Jenkins job -
/jenkins build jobname
- Trigger a build for the given job. If the job accepts parameters, an interactive dialog pops up for the user to input the required parameters.- If the job resides in a folder, specify the job as
folder1/jobname
. Note the slash character. - If the folder name or job name has spaces in it, wrap the jobname in double quotes as
"job name with space"
or"folder with space/jobname"
. - Follow similar pattern for all commands which takes jobname as input.
- If the job resides in a folder, specify the job as
-
Abort a build -
/jenkins abort jobname <build number>
- Abort the given build of the specified job. Ifbuild number
is not specified, the command aborts the last build of the job. -
Enable a job -
/jenkins enable jobname
- Enable a given Jenkins job. -
Disable a job -
/jenkins disable jobname
- Disable a given Jenkins job. -
Delete a job -
/jenkins delete jobname
- Delete a given job. -
Get artifacts -
/jenkins get-artifacts jobname
- Get artifacts of the last build of the given job. -
Get test results -
/jenkins test-results jobname
- Get test results of the last build of the given job. -
Get build log -
/jenkins get-log jobname <build number>
- Get log of a given build of the specified job as a file attachment to the channel. Ifbuild number
is not specified, the command fetches the log of the last build of the job.
- List of installed plugins -
/jenkins plugins
- Get a list of installed plugins on Jenkins server along with the version of the plugin.
- Safe restart Jenkins server -
/jenkins safe-restart
- Safe restart the Jenkins server. - Find connected Jenkins account -
/jenkins me
- Display the connected Jenkins account. - Get help -
/jenkins help
- Find help related to the syntax of the slash commands.
- Install the plugin
- Download the latest version of the plugin from the GitHub releases page
- In Mattermost, go to System Console -> Plugins -> Management
- Upload the plugin
- Enter Jenkins server URL
- Go to the System Console -> Plugins -> Jenkins
- Set the Jenkins server URL along with the protocol. Example: http://jenkins.example.com, https://jenkins.example.com
- Save the settings
- Generate an at rest encryption key
- Go to the System Console -> Plugins -> Jenkins and click "Regenerate" under "At Rest Encryption Key"
- Save the settings
- Enable the plugin
- Go to System Console -> Plugins -> Management and click "Enable" underneath the Jenkins plugin
- Test it out
- In Mattermost, run the slash command
/jenkins connect <Jenkins Username> <Jenkins API Token>
- In Mattermost, run the slash command
make
This will produce a single plugin file (with support for multiple architectures) that can be uploaded to your Mattermost server:
dist/jenkins-0.0.x.tar.gz
After the plugin is built, deploy it using Mattermost system console and test it out.
How do I generate API Token for a given Jenkins user?
Since Jenkins 2.129 the API token configuration has changed:
You can now have multiple tokens and name them. They can be revoked individually.
- Log in to Jenkins.
- Click you name (upper-right corner).
- Click Configure (left-side menu).
- Use "Add new Token" button to generate a new one then name it.
- You must copy the token when you generate it as you cannot view the token afterwards.
- Revoke old tokens when no longer needed.
Before Jenkins 2.129: Show the API token as follows:
- Log in to Jenkins.
- Click your name (upper-right corner).
- Click Configure (left-side menu).
- Click Show API Token.
Source : https://stackoverflow.com/a/45466184/6852930
MIT