Created
June 27, 2017 12:43
-
-
Save aslakhellesoy/d026d984765d7f63203085df06bc42eb to your computer and use it in GitHub Desktop.
Find failed build task in Circle build - Zapier function
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
fetchBuild(inputData.buildNum, CIRCLE_TOKEN) | |
.then(failedAction) | |
.then(function(action) {callback(null, {'Failed Action': action})}) | |
.catch(function(err) {callback(err)}) | |
function fetchBuild(buildNum, circleToken) { | |
return fetch( | |
'https://circleci.com/api/v1.1/project/github/cucumber-ltd/cucumber-pro/' + | |
buildNum + | |
'?circle-token=' + | |
circleToken | |
).then(function(res) {return res.json()}) | |
} | |
function failedAction(build) { | |
var step = build.steps.find(function(step) { | |
return step.actions.find(function(action) { | |
return action.exit_code && action.exit_code !== 0 | |
}) | |
}) | |
return step ? step.name : null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment