Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Gradle task to push CircleCI build notifications to Slack
task circleci_artifact_to_slack {
doLast {
println 'Retrieving APK from CircleCI'
String buildNumber = System.getenv("CIRCLE_BUILD_NUM")
String branch = System.getenv("CIRCLE_BRANCH")
String buildUrl = System.getenv("CIRCLE_BUILD_URL")
String url = "$buildNumber/artifacts?circle-token=YOUR_TOKEN"
def artifacts = new JsonSlurper().parseText(url.toURL().text)
String artifactUrl = artifacts["url"][0]
String slackToken = System.getenv("SLACK_TOKEN")
def post = ["curl", "-X", "POST", "--data-urlencode", "payload={\"channel\": \"#not_android_ci\", \"username\": \"CIRCLECI\", \"text\": \" Build $buildNumber at $buildUrl\nfor branch *$branch*\nAPK: $artifactUrl \", \"icon_emoji\": \":android:\"}", "$slackToken"].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment