It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to Receive Jenkins Build Notifications in Stride - Freestyle Projects

image2018-5-24_13-8-23.png

Before you start

Be sure you have the following plugins in Jenkins:

Check out our example files in Bitbucket.

For Jenkins pipeline projects see  "How to Receive Jenkins Build Notifications in Stride" 

Copy the access token and conversation URL

  1. In your Stride room or direct message, click apps.png(Apps) in the sidebar, then click plus-add.png.
  2. Click Add custom app > API tokens.
  3. Give the token a name. We recommend Jenkins.
  4. Copy the access token and paste it in a safe place.
  5. Copy the conversation url and paste it into the same place.

Add global scripts to Jenkins

  1. Open your Jenkins Web Portal.
  2. Click Manage Jenkins.
  3. Click Managed Files.
  4. Click Add a New Config.
  5. Choose the Managed script file type.
  6. Optional: Enter the file name as the in the Id field. This makes it scripts easier to reference in a Jenkinsfile if any of your projects using them. 
  7. Click Submit.
  8. Put a human-readable name in the Name field
  9. Paste in the contents of the script
  10. Replace STRIDE_TOKEN_GOES_HERE and STRIDE_CONVERSATION_URL_GOES_HERE with the access token and conversation URL you saved (see the previous section).
  11. Submit the form
  12. Repeat these steps for each notification type wanted

 

notify_stride.started.sh

set +x -u

curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer STRIDE_TOKEN_GOES_HERE' \
-d "{\"content\":[{\"attrs\":{\"collapsible\":true,\"context\":{\"icon\":{\"label\":\"Jenkins Build Server\",\"url\":\"https://jenkins.io/sites/default/files/jenkins_favicon.ico\"},\"text\":\"Jenkins Build Server - ${JOB_NAME} ${BUILD_DISPLAY_NAME} - BUILD STARTED\"},\"description\":{\"text\":\"Tag: ${BUILD_TAG}    Commit:${GIT_COMMIT}\"},\"details\":[{\"lozenge\":{\"appearance\":\"inprogress\",\"text\":\"BUILD STARTED\"}},{\"lozenge\":{\"appearance\":\"inprogress\",\"text\":\"${BUILD_DISPLAY_NAME}\"},\"title\":\"Build Number\"}],\"link\":{\"url\":\"${RUN_DISPLAY_URL}\"},\"text\":\"${JOB_NAME} - BUILD STARTED\",\"title\":{\"text\":\"${JOB_NAME} - BUILD STARTED\",\"user\":{\"icon\":{\"url\":\"https://jenkins.io/sites/default/files/jenkins_favicon.ico\",\"label\":\"Build Started\"}}}},\"type\":\"applicationCard\"}],\"type\":\"doc\",\"version\":1}" \
--url STRIDE_CONVERSATION_URL_GOES_HERE

notify_stride.success.sh

set +x -u

curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer STRIDE_TOKEN_GOES_HERE' \
-d "{\"content\":[{\"attrs\":{\"collapsible\":true,\"context\":{\"icon\":{\"label\":\"Jenkins Build Server\",\"url\":\"https://jenkins.io/sites/default/files/jenkins_favicon.ico\"},\"text\":\"Jenkins Build Server - ${JOB_NAME} ${BUILD_DISPLAY_NAME} - BUILD SUCCEEDED\"},\"description\":{\"text\":\"Tag: ${BUILD_TAG}    Commit:${GIT_COMMIT}\"},\"details\":[{\"lozenge\":{\"appearance\":\"success\",\"text\":\"BUILD SUCCEEDED\"}},{\"lozenge\":{\"appearance\":\"success\",\"text\":\"${BUILD_DISPLAY_NAME}\"},\"title\":\"Build Number\"}],\"link\":{\"url\":\"${RUN_DISPLAY_URL}\"},\"text\":\"${JOB_NAME} - BUILD SUCCEEDED\",\"title\":{\"text\":\"${JOB_NAME} - BUILD SUCCEEDED\",\"user\":{\"icon\":{\"url\":\"https://jenkins.io/sites/default/files/jenkins_favicon.ico\",\"label\":\"BUILD SUCCEEDED\"}}}},\"type\":\"applicationCard\"}],\"type\":\"doc\",\"version\":1}" \
--url STRIDE_CONVERSATION_URL_GOES_HERE

notify_stride.failure.sh

set +x -u

curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer STRIDE_TOKEN_GOES_HERE' \
-d "{\"content\":[{\"attrs\":{\"collapsible\":true,\"context\":{\"icon\":{\"label\":\"Jenkins Build Server\",\"url\":\"https://jenkins.io/sites/default/files/jenkins_favicon.ico\"},\"text\":\"Jenkins Build Server - ${JOB_NAME} ${BUILD_DISPLAY_NAME} - BUILD FAILED\"},\"description\":{\"text\":\"Tag: ${BUILD_TAG} Commit:${GIT_COMMIT}\"},\"details\":[{\"lozenge\":{\"appearance\":\"removed\",\"text\":\"BUILD FAILED\"}},{\"lozenge\":{\"appearance\":\"removed\",\"text\":\"${BUILD_DISPLAY_NAME}\"},\"title\":\"Build Number\"}],\"link\":{\"url\":\"${RUN_DISPLAY_URL}\"},\"text\":\"${JOB_NAME} - BUILD FAILED\",\"title\":{\"text\":\"${JOB_NAME} - BUILD FAILED\",\"user\":{\"icon\":{\"url\":\"https://jenkins.io/images/angry-jenkins_128.png\",\"label\":\"BUILD FAILED\"}}}},\"type\":\"applicationCard\"}],\"type\":\"doc\",\"version\":1}" \
--url STRIDE_CONVERSATION_URL_GOES_HERE

 

Configure the Jenkins Freestyle Project

Build Started Notification

  1. Open your Jenkins Web Portal
  2. Open your projects configuration screen
  3. In the Build section, click Add build step and select Execute managed script
  4. Find your script name for notify_stride.started.sh and select it

Build Failed Notification

  1. Open your Jenkins Web Portal
  2. Open your projects configuration screen
  3. In the Post-build Actions section, click Add post-build action and select Execute scripts
  4. Click Add post build step and select All except SUCCESS in the list (Ctrl+click on windows, Cmd+click on Mac)
  5. Click Add build step and select Execute managed script
  6. Find your script name for notify_stride.faliure.sh and select it

Build Success Notification

  1. Open your Jenkins Web Portal
  2. Open your projects configuration screen
  3. In the Post-build Actions section, click Add post-build action and select Execute scripts
  4. Click Add post build step and select SUCCESS in the list
  5. Click Add build step and select Execute managed script
  6. Find your script name for notify_stride.success.sh and select it

 

Configuration Example Images

Build Section properly configured

image2018-5-24_13-42-23.png

 

Post-build Actions Section properly configured

image2018-5-24_13-39-59.png

3 comments

The notify_stride.failure.sh script is not correct, because it uses the same code as notify_stride.started.sh script. 

Thanks for this instruction!

Jon Ross Atlassian Team Jun 14, 2018

Thanks@Oleh Sevriukov! I've updated the script to fix my copy paste blunder. 

posted in wrong place, deleting and posting in Jira issue.

Comment

Log in or Sign up to comment
Community showcase
Published in Stride

Stride and Hipchat Cloud have reached End of Life (updated)

All good things come to an end - thanks to all our customers and partners who have been along the Hipchat and Stride journey with us.  As of Feb 15th 2019, Hipchat Cloud and Stride have reached ...

2,414,672 views 26 23
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you