Skip to content

Instantly share code, notes, and snippets.

@jimCresswell
Last active September 8, 2018 00:06
Show Gist options
  • Select an option

  • Save jimCresswell/7007372 to your computer and use it in GitHub Desktop.

Select an option

Save jimCresswell/7007372 to your computer and use it in GitHub Desktop.
Node script for parsing a Github web hook payload in Jenkins and extracting the commit hash.
#!/usr/bin/env node
// Grab environment variables
var payloadString = process.env.payload;
// If no payload was received there is nothing to do. Not allowed to use "null".
if (payloadString === "nodata") { // This assume the default payload parameter value is "nodata". Not allowed to use "null".
return 0;
}
// Parse JSON
var payloadObject = JSON.parse(payloadString);
var latestCommitHash = payloadObject.pull_request.head.sha;
console.log("Found latest commit: " + latestCommitHash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment