This documentation relates to QuickBuild 8.0.x
Select here if you are using a different version

Webhooks

Version 2 by Steve Luo
on Jul 28, 2018 15:17.


compared with
Version 3 by Steve Luo
on Jul 28, 2018 15:21.


Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 1 changes. View first change.

 {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.
  
  
  Webhooks are configuration-related. You can go to configuration settings to configure the webhooks:
  
 !webhooks.png!
  
  
 h3. Event
  
 The build events include:
  
 * BUILD_STARED when build is stared
 * BUILD_FINISHED when build is finished
  
 h3. Payload
  
 Each event type has the same payload format like below:
  
  
 {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}