Created
May 5, 2017 00:39
-
-
Save slamb2k/28f1b8ff910ea9051f5d541199e86d62 to your computer and use it in GitHub Desktop.
MobileCenterBuildDownload
This file contains 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
function downloadOutput(buildId) { | |
util.debug("Getting build output for Build Id: {0}", buildId); | |
// Construct build output Url | |
var buildOutputUrl = `${mobileCenterBaseUrl}/builds/${buildId}/downloads/build`; | |
var options = { | |
url: buildOutputUrl, | |
headers: { | |
"X-API-Token": apiToken, | |
"Accept": "application/json", | |
"Content-Type": "application/json" | |
} | |
}; | |
return request(options) | |
.then(function (body) { | |
// Parse the response so we can get the build detail | |
var buildOutputDetail = JSON.parse(body); | |
return (buildOutputDetail.uri); | |
}).then(function (uri) { | |
var file = fs.createWriteStream(MobileCenterBuildArtifacts); | |
var downloadRequest = request(uri).pipe(file); | |
downloadRequest.on('error', function (err) { util.debug("Error downloading build output: {0}", err); }); | |
downloadRequest.on('finish', function () { file.close(function () { util.debug("Download complete: {0}", MobileCenterBuildArtifacts); }) }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment