Skip to content

Instantly share code, notes, and snippets.

@aslakhellesoy
Created June 27, 2017 12:43
Show Gist options
  • Save aslakhellesoy/d026d984765d7f63203085df06bc42eb to your computer and use it in GitHub Desktop.
Save aslakhellesoy/d026d984765d7f63203085df06bc42eb to your computer and use it in GitHub Desktop.
Find failed build task in Circle build - Zapier function
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