View Source

{info}
Since 8.0.12
{info}

Webhooks allow you to subscribe to build events on your QuickBuild instance. When one of those events is triggered, we'll send a HTTP POST payload to the webhook's configured URL.


You can set up Webhooks for one configuration as many as you want. The configuration setting looks like below:

!webhook.png!


h3. Event

The build events include:

* BUILD_STARED when build is stared
* BUILD_FINISHED when build is finished
* BUILD_RECOMMENDED when build is recommended
* BUILD_UNRECOMMENDED when build is un-recommended

h3. Payload

The payload data can be any JSON string. If it is empty, the build model will be delivered.

Below is an example of build model:


{code}
{
"configurationId": 123, // configuration id
"configurationPath": "root/PMEase/Quickbuild", // configuration path
"id": 345, // build id
"version": "1.3.4",
"status": "RUNNING", // build status, can be: SUCCESSFUL, RECOMMENDED, FAILED, CANCELLED, TIMEOUT, RUNNING
"requester": "admin",
"duration": 100, // in milliseconds
"beginDate": "20180728T03:51:58.573+0000", // in ISO8601 format, yyyyMMdd'T'HH:mm:ss.SSSZ
"endDate": "20180728T03:51:58.573+0000", // in ISO8601 format, yyyyMMdd'T'HH:mm:ss.SSSZ
}
{code}


h3. Delivery headers

HTTP POST payloads that are delivered to your webhook's configured URL endpoint will contain several special headers:

|| Header || Description ||
| X-QB-EventType | Name of the event type that triggered the delivery, can be: BUILD_STARTED, BUILD_FINISHED |
| X-QB-Signatuer | The HMAC hex digest of the response body. This header will be sent if the webhook is configured with a secret. The HMAC hex digest is generated using the sha1 hash function and the secret as the HMAC key. |

h4. HMAC signature

Below is an example with Java on how to create the signature:

{code}
public class HmacSha1Signature {
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

private static String toHexString(byte[] bytes) {
try (Formatter formatter = new Formatter()) {
for (byte b : bytes) {
formatter.format("%02x", b);
}

return formatter.toString();
}
}

public static String calculateRFC2104HMAC(String data, String key)
throws SignatureException, NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
return toHexString(mac.doFinal(data.getBytes()));
}

}

{code}