This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcparams.js
75 lines (55 loc) · 1.95 KB
/
tcparams.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use strict";
var request = require('request');
/*
options
{
teamCityHost: <string> 'http://host:port',
parameterNames: [<string>] 'env.ParameterName',
buildTypeIds: <array> ['bt12','bt22', 'etc']
}
*/
exports.queryTeamCityParameters = function (options, callback) {
if (typeof callback != 'function')
throw "queryTeamCityParamters expects a callback parameter"
if (!options.emptyParameterValue)
options.emptyParameterValue = "<MISSING>";
options.buildTypeIds.forEach(function (id) {
var uri = options.teamCityHost + "/httpAuth/app/rest/buildTypes/id:";
var requestOptions = {
uri: uri + id,
json: true,
auth: {
user: options.user,
pass: options.password,
sendImmediately: false
}
};
request(requestOptions, function (error, response, body) {
if (error != null) {
callback(error, null);
return;
}
if (typeof body != 'object') {
console.log(body);
callback("Oops! We didn't get a json result back from\n" + requestOptions.uri, null);
return;
}
var parameters = body.parameters;
options.parameterNames.forEach(function (parameterName) {
var parameterValue = options.emptyParameterValue,
found = false;
parameters.property.forEach(function (parameter) {
if (parameter.name == parameterName) {
parameterValue = parameter.value;
found = true;
}
});
callback(null, {
parameterName: parameterName,
buildTypeId: id,
parameterValue: parameterValue
});
});
});
});
}