Skip to content
Jenkins pipeline steps for integration with Hubot.
Java CoffeeScript HTML
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
scripts
src JENKINS-57016: add parameters functionality to hubot-steps plugin (#26) Jul 20, 2019
.gitignore Release Review 2.0.4, prepare for next dev version (#24) Mar 6, 2019
CHANGELOG.adoc Update CHANGELOG.adoc Jul 20, 2019
CONTRIBUTING.adoc
Jenkinsfile
LICENSE
NOTICE JENKINS-50026 Hubot Steps 2.0.0 (#11) Apr 7, 2018
PULL_REQUEST_TEMPLATE.md
README.adoc Few spelling corrections (#22) Mar 2, 2019
pom.xml Use HTTPS URLs in pom.xml (#28) Oct 8, 2019

README.adoc

Hubot Pipeline Steps

Configuration

Hubot Site

  • Default Site optional, default to false. Default at folder level or Global level, when there are multiple default sites at the same level (Global or at a certain folder level), randomly picked.

  • Name required, site name.

  • URL required, hubot url, including port number, Ex: https://localhost:9999/.

  • Room optional, room name, which can include #, depends on the chat service. Is optional when using folder name as room option.

  • Use Folder Name as Room optional, by default is false, use folder name as room name.

  • Room Prefix optional, only applicable for folder name as room option enabled. Ex: For personal organization folder @ required to send direct messages.

  • Fail On Error optional, default true.

  • Advanced

    • Build Notifications optional - List of build notifications.

      • Enabled - Enable this notification.

      • Type - List of available build notifications.

      • Room(s) - optional, list of rooms, comma separated, when it is different from actual room name above.

      • Token(s) - optional, list of tokens, comma separated, refer to Token Macro plugin for more info. Ex: 'BUILD_DURATION, BUILD_URL'. NOTE: no ${} around token name.

Global Config

  • List of Global Hubot Sites

Global Site

Folder Config

  • List of Hubot Sites

Folder Site

Job Config

  • Enable Notifications - defaults to false.

  • Hubot Site Name optional, given there is a default site at folder(or one of the parent folders) level/ global level.

Job Config

Build Notifications

Supports sending notifications for the following build statuses.

  • Build Started.

  • Build Aborted.

  • Build Successful.

  • Build Failed.

  • Build Unstable.

  • Build Back to Normal.

  • Module not built.

Build Notifications

Pipeline Steps

The following Jenkins pipeline steps are available.

hubotSend

Sends a given message to site/room.

hubotSend message: 'Releasing Test project.'
  • message required, actual message to send.

  • status optional, text which can be used in script to differentiate. Ex: INFO, WARN, ERROR or SUCCESS - So that in Slack it can be used to decide card colors.

  • tokens optional, list of tokens, comma separated, Refer to Token Macro plugin for more information.

  • extraData optional, extra data like attachments in case of slack, Any kind of Map, given it is Serializable.

  • site optional, hubot site name either it is from Folder Level or Global Level, Only used when url is not present. Optional, it will fallback to first default site that it found while searching from immediate folder to Global site configurations.

  • url optional, if it is provided as global environment variable HUBOT_URL or provided by withEnv step, this should always end with /, environment variable takes the lower precedence.

  • room optional, if it is provided as global environment variable HUBOT_DEFAULT_ROOM or provided by withEnv step, and room doesn’t require #, it is added in the code, environment variable takes the lower precedence.

  • failOnError optional and by default it is true, if any error it won’t abort the job, it can also be provided as global environment variable HUBOT_FAIL_ON_ERROR, environment variable takes the lower precedence.

hubotApprove

Sends a hubot message the project chat room for a project when the build is waiting for user input with the hubot commands to proceed or abort the build.

hubotApprove message: 'Promote to Production?'
  • message required, actual message to send.

  • status optional, text which can be used in script to differentiate. Ex: INFO, WARN, ERROR or SUCCESS - So that in Slack it can be used to decide card colors.

  • tokens optional, list of tokens, comma separated, Refer to Token Macro plugin for more information.

  • extraData optional, extra data like attachments in case of slack, Any kind of Map, given it is Serializable.

  • site optional, hubot site name either it is from Folder Level or Global Level, Only used when url is not present. Optional, it will fallback to first default site that it found while searching from immediate folder to Global site configurations.

  • url optional, if it is provided as global environment variable HUBOT_URL or provided by withEnv step, this should always end with /, environment variable takes the lower precedence.

  • room optional, if it is provided as global environment variable HUBOT_DEFAULT_ROOM or provided by withEnv step, and room doesn’t require #, it is added in the code, environment variable takes the lower precedence.

  • failOnError optional and by default it is true, if any error it won’t abort the job, it can also be provided as global environment variable HUBOT_FAIL_ON_ERROR, environment variable takes the lower precedence.

  • id optional, defaults to Proceed, refer to input step for more information.

  • submitter optional, comma separated list of users who can provide input. Refer to input step for more information.

  • ok optional, Proceed button label, Refer to input step for more information.

  • submitterParameter optional If specified, this is the name of the return value that will contain the ID of the user that approves this input. Refer to input step for more information.

  • parameters optional, Request that the submitter specify one or more parameter values when approving. Refer to input step for more information.

Example

hubotSend message: "*Release Started*. \n Releasing Test Project. :sunny: \n<!here> <!channel> <@nrayapati> ", tokens: "BUILD_NUMBER,BUILD_ID", status: 'STARTED'

hubotSend message: "*Release Completed*. \n Releasing Test Project.", tokens: "BUILD_NUMBER,BUILD_ID", status: 'SUCCESS'

hubotApprove message: 'Promote to Staging?', tokens: "BUILD_NUMBER, BUILD_DURATION", status: 'ABORTED'

hubotSend message: "*Staging Deployment Successful...* \n Deployed Test Project to 192.168.1.175 node.", tokens: "BUILD_NUMBER,BUILD_ID", status: 'SUCCESS'

hubotApprove message: 'Promote to Production?', tokens: "BUILD_NUMBER, BUILD_DURATION", status: 'ABORTED'

hubotSend message: "*Hooray! Went to Prod... :satisfied:* \n Deployed Test Project to prod(10.12.1.191) node.", tokens: "BUILD_NUMBER,BUILD_ID", status: 'SUCCESS'

Jenkins Approved Job

Slack Example
Slack Example

Jenkins Aborted Job:

Slack Example
Slack Example

Hubot Setup

New to hubot?

Refer to hubot-base to setup a either docker container or to run it locally.

💡
Please replace scripts on hubot-base repo with the scripts under this hubot-steps repo and it is always a good idea to copy over the scripts from appropriate tag based on the version being installed on Jenkins.

Already running hubot.

Then just copy over following scripts from scripts folder (jenkins, and one of the hubot scripts based on chat service you are using.). These are just examples and can be modified based on chat service / per the actual needs.

Examples

Default Site at Folder/Global level.

hubotSend message: 'test message.'
hubotApprove message: 'Proceed with building this job?'

With Site Name either at Folder or Global level.

hubotSend message: 'test message.', site: 'release'
hubotApprove message: 'Proceed with building this job?', site: 'release'

Site with Folder Name as Room.

hubotSend message: 'test message.', site: 'release'
hubotApprove message: 'Proceed with building this job?', site: 'release'

With Global Environment Variables / No Default Site at Folder/Global level.

Global
hubotSend message: 'test message.'
hubotApprove message: 'Proceed with building this job?'

withEnv Variables / No Default Site at Folder/Global level.

withEnv(['HUBOT_URL=http://192.168.1.176:9999','HUBOT_DEFAULT_ROOM=botlab','HUBOT_FAIL_ON_ERROR=false']) {
  hubotSend message: 'building job $BUILD_URL'
  hubotApprove message: 'Proceed with building this job?'
}

No Environment Variables

Screenshot:

Pipeline Syntax
hubotSend failOnError: 'false', message: 'testMessage', room: 'botlab', url: 'http://192.168.1.176:9999/'
hubotApprove failOnError: 'false', message: 'Proceed with building this job?', room: 'botlab', url: 'http://192.168.1.176:9999/'

Blue Ocean View

BlueOcean

Known Issues

  • hubot script doesn’t work when Prevent Cross Site Request Forgery exploits enabled in Configure Global Security, need to modify script to query crumb before actual request.

Maintainers

Disclaimer

Please don’t hesitate to log a JIRA or github pull request if you need any help or if you can be of help with this plugin :). Refer to the contribution guide for more information.

Developed by Naresh Rayapati, this repo was initially cloned from ThoughtsLive

You can’t perform that action at this time.