Skip to content

Instantly share code, notes, and snippets.

Embed
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 = "https://circleci.com/api/v1.1/project/github/YOUR_REPO/$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:\"}", "https://hooks.slack.com/services/$slackToken"].
execute()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.