Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Oleh Sevriukov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2018

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!

???ℜ???
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2018

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

Jon Starbird
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 9, 2018

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

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events