-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const https = require('https')
const buildOptions = (event) => {
const {vcsType, project, branch, circleToken} = event
return {
hostname: 'circleci.com',
port: 443,
path: `/api/v1.1/project/${vcsType}/${project}/tree/${branch}?circle-token=${circleToken}`,
method: 'POST',
headers: {
'content-type': 'application/json',
'cache-control': 'no-cache'
}
}
}
const postContent = JSON.stringify({
build_parameters: {
RUN_NIGHTLY_BUILD: true,
// add your build parameters here!
}
})
exports.handler = (event, context, callback) => {
const options = buildOptions(event)
console.log(options)
const req = https.request(options, (res) => {
let body = ''
console.log('statusCode:', res.statusCode)
console.log('headers:', res.headers)
if (res.statusCode !== 201) {
context.fail('Build schedule failed')
callback('error', res.statusCode)
}
res.on('data', (chunk) => body += chunk)
res.on('end', () => {
console.log('Successfully processed HTTPS response')
context.succeed()
callback(null, body)
})
})
req.on('error', callback)
req.write(postContent)
req.end()
}