Created
July 17, 2018 16:55
-
-
Save reitzig/e24dcb60818eb010a3b2b255df1f4bd5 to your computer and use it in GitHub Desktop.
Report Jenkins build status to Upsource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent any | |
environment { | |
UPSOURCE_URL = "http://your.upsource" | |
UPSOURCE_PROJECT = "your-project" | |
UPSOURCE_AUTH = credentials('upsource-auth') | |
// ^^ set this up as "secret text" credential in Jenkins; | |
// use the authentication token from Upsource project settings > integration | |
} | |
stages { | |
stage('Prepare') { | |
steps { | |
sh script: 'notify_upsource.sh in_progress' | |
// prepare stuff | |
} | |
} | |
// further stages | |
} | |
post { | |
success { | |
sh script: 'notify_upsource.sh success' | |
} | |
aborted { | |
sh script: 'notify_upsource.sh failed' | |
} | |
failure { | |
sh script: 'notify_upsource.sh failed' | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Send a build status notification to Upsource | |
# | |
# References: | |
# | |
# - https://www.jetbrains.com/help/upsource/ci-server-integration.html#OtherCIservers | |
# - https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables | |
# | |
# Note: $UPSOURCE_* are set using environment in Jenkinsfile | |
if [[ -z "${UPSOURCE_AUTH}" ]]; then | |
echo "Upsource authentication token not set." | |
exit 1 | |
fi | |
echo "{ | |
\"key\" : \"${BUILD_TAG}\", | |
\"name\": \"#${BUILD_NUMBER}\", | |
\"state\": \"${1}\", | |
\"url\": \"${BUILD_URL}\", | |
\"project\": \"${UPSOURCE_PROJECT}\", | |
\"revision\": \"${GIT_COMMIT}\" | |
}" | \ | |
curl -X POST \ | |
--data @- \ | |
"${UPSOURCE_URL}/~buildStatus/" \ | |
--header "Content-Type: application/json; charset=UTF-8" \ | |
--header "Authorization: Basic ${UPSOURCE_AUTH}" | |
if [ $? == 0 ] ; then | |
echo "Notified Upsource of ${1}" | |
fi |
This was really useful, thank you. Note that with latest Upsource version, the state string has to be an enum of 'Success', 'Failed' or 'InProgress'.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a skeleton for a Jenkins Declarative Pipeline that reports the build status to Upsource.
Requires
curl
to be installed on the build agent.Gotcha: Currently, the status is lost if Upsource re-indexes the project after the build is complete. Reported as UP-9968.