DUMBCODE
GradleHook is a gradle plugin that adds a POST request as a gradle task.
Wyn Price
Developer
Adds the postRequest
task which simply posts a POST request along with the specified builds. Additional fields for the request can be specified. The request uses the user agent Mozilla/5.0
and has the content-type of multipart/form-data
.
Using the plugin DSL:
plugins {
id "net.dumbcode.gradlehook" version "1.2.0"
}
Using the legacy plugin application:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
dependencies {
classpath "net.dumbcode.gradlehook:GradleHook:1.2.0"
}
}
apply plugin: "net.dumbcode.gradlehook"
The bare minimum of a plugin using gradlehook
gradlehook {
urlToken "http://example.com/webhook" //Keep private.
addArtifact jar
}
You can apply multiple tasks to be sent over. In this senario 2 files would be sent.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
gradlehook {
urlToken "http://example.com/webhook"
addArtifact jar
addArtifact sourcesJar
}
When sending the request, you might want to add additional data. This can be done with the addField method. For example, sending a webhook to a discord server would be:
gradlehook {
urlToken 'https://discordapp.com/api/webhooks/012345678912345678/foobar' //keep private
addField 'payload_json', '{ "embeds": [{ "timestamp": "{{datetime}}" }] }'
addArtifact jar
}
The fields are able to have placeholders, as shown in the above example. These placeholders mean the following:
{{version}}
project version{{name}}
project name{{group}}
project group{{dateTime}}
the current time in UTC, in ISO-8601 formatIn some senarios, you want the text message to sent as a seperate webhook before the build webhooks. The following would mean a webhook with the field "id" would be sent, then once an HTTP_OK response code is sent, the artifacts are sent over in a webhook.
gradlehook {
urlToken "http://example.com/webhook"
addField 'id', 'user2201'
addArtifact jar
messageFirst
}
GradleHook is licensed under MIT with no exceptions.