-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathadd-vcs-project.cs
85 lines (76 loc) · 2.3 KB
/
add-vcs-project.cs
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
76
77
78
79
80
81
82
83
84
85
//@req(user, token, url, branch, type)
//git repo url normalization
url = url.replace(/^\s+|\s+$/gm, ''),
contextsExists = "";
var ind = url.lastIndexOf(".git");
if (ind == -1 || ind != url.length - 4) {
ind = url.lastIndexOf("/");
if (ind > -1 && ind == url.length - 1) url = url.substring(0, ind);
url = toNative(url + ".git");
}
contexts = type == "ruby" ? ["development", "test", "production"] : ["ROOT"];
p = {
session: session,
envName: "${env.envName}",
nodeGroup: "${targetNodes.nodeGroup}",
type: "git",
url: url,
branch: branch,
login: user,
password: token,
keyId: null,
context: contexts[0],
autoupdate: false,
interval: 1,
autoResolveConflict: true,
zdt: false
}
resp = jelastic.env.control.GetEnvInfo("${env.envName}", session);
if (resp && resp.result != 0) return resp;
if (resp.env && resp.env.contexts) {
contextsExists = resp.env.contexts.length;
}
if (contextsExists) {
//removing already deployed app/project in context
//specifically for ruby -> removing all contexts (development, test and production),
//because ruby supports only one context at a time
for (i = 0; i < contexts.length; i++) {
resp = jelastic.env.control.RemoveApp(p.envName, p.session, contexts[i]);
if (resp.result != 0 && resp.result != 2313) return resp;
resp = jelastic.env.vcs.DeleteProject(p.envName, p.session, contexts[i]);
if (resp.result != 0 && resp.result != 2500) return resp;
}
}
//create and update the project
resp = jelastic.env.vcs.CreateProject({
envName: p.envName,
nodeGroup: p.nodeGroup,
session: p.session,
type: p.type,
context: p.context,
url: p.url,
branch: p.branch,
keyId: p.keyId,
login: p.login,
password: p.password,
autoupdate: p.autoupdate,
interval: String(p.interval),
autoResolveConflict: p.autoResolveConflict,
zdt: p.zdt
});
if (resp.result != 0) {
resp.params = p;
return resp;
}
//github triggers first update automatically after we add a webhook
//calling update action manually for non-github repos
if (url.indexOf("github.com") == -1) {
var params = {
envName: p.envName,
session: p.session,
context: p.context,
delay: getParam("delay") || 30
}
resp = jelastic.env.vcs.Update(params);
}
return resp;