-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrigger-azure-pipeline.js
More file actions
48 lines (43 loc) · 1.49 KB
/
trigger-azure-pipeline.js
File metadata and controls
48 lines (43 loc) · 1.49 KB
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
const https = require('https');
const triggerAzurePipeline = async (token, organization, project, buildDefinitionId, sourceBranch, parameters) => {
const auth = Buffer.from('PAT:' + token).toString('base64');
const headers = {
'Accept': 'application/json; api-version=5.0-preview.5; excludeUrls=true',
'Authorization': 'Basic ' + auth,
};
const json = JSON.stringify({
'definition': { 'id': buildDefinitionId },
'sourceBranch': sourceBranch,
'parameters': JSON.stringify(parameters),
});
headers['Content-Type'] = 'application/json';
headers['Content-Length'] = Buffer.byteLength(json);
const requestOptions = {
host: 'dev.azure.com',
port: '443',
path: `/${organization}/${project}/_apis/build/builds?ignoreWarnings=false&api-version=5.0-preview.5`,
method: 'POST',
headers: headers
};
return new Promise((resolve, reject) => {
const handleResponse = (res) => {
res.setEncoding('utf8');
var response = '';
res.on('data', (chunk) => {
response += chunk;
});
res.on('end', () => {
resolve(JSON.parse(response));
});
res.on('error', (err) => {
reject(err);
})
};
const request = https.request(requestOptions, handleResponse);
request.write(json);
request.end();
});
}
module.exports = {
triggerAzurePipeline
}