Last active
September 8, 2018 00:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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