-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.js
177 lines (161 loc) · 5.61 KB
/
update.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const execShPromise = require("exec-sh").promise;
let fs = require("fs");
const projects = [
/*{ name: "202210_S1_E1_OlimpicosInvierno_Front" },*/
{ name: "202210_S1_E2_CocinasMundo_Front" },
{ name: "202210_S1_E3_SitiosTuristicos_Front" },
{ name: "202210_S1_E4_MuseoArteModerno_Front" },
{ name: "202210_S1_E5_AutosClasicos_Front" },
{ name: "202210_S2_E1_MundialesFutbol_Front" },
{ name: "202210_S2_E2_LigaAjedrez_Front" },
{ name: "202210_S2_E3_Discomovil_Front" },
{ name: "202210_S2_E4_ParqueAutomotor_Front" },
{ name: "202210_S2_E5_Agenda_Front" },
{ name: "202210_S3_E1_Musica_Front" },
{ name: "202210_S3_E2_Trekking_Front" },
{ name: "202210_S3_E3_DogSpa_Front" },
{ name: "202210_S3_E4_Kindergarten_Front" },
];
const createRepos = async () => {
let out;
try {
for (const project of projects) {
const jenkinsFile = getJenkinsFile(project.name);
const sonarFile = getSonarFile(project.name);
fs.writeFileSync("Jenkinsfile", jenkinsFile);
fs.writeFileSync("sonar-project.properties", sonarFile);
let command1 = `hub create Uniandes-isis2603/${project.name}`;
out = await execShPromise(command1, true);
}
} catch (e) {
console.log("Error: ", e);
console.log("Stderr: ", e.stderr);
console.log("Stdout: ", e.stdout);
return e;
}
console.log("out: ", out.stdout, out.stderr);
};
const updateRepos = async () => {
let out;
try {
for (const project of projects) {
const jenkinsFile = getJenkinsFile(project.name);
const sonarFile = getSonarFile(project.name);
fs.writeFileSync("Jenkinsfile", jenkinsFile);
fs.writeFileSync("sonar-project.properties", sonarFile);
let command1 = `git remote rm origin &&
git remote add origin [email protected]:Uniandes-isis2603/${project.name}.git &&
echo ".dummyfile" > .dummyfile &&
git add . &&
git commit -m "Update Jenkinsfile" &&
git push origin master`;
out = await execShPromise(command1, true);
}
} catch (e) {
console.log("Error: ", e);
console.log("Stderr: ", e.stderr);
console.log("Stdout: ", e.stdout);
return e;
}
console.log("out: ", out.stdout, out.stderr);
};
//createRepos();
updateRepos();
function getSonarFile(repo) {
const content = `sonar.host.url=http://157.253.238.75:8080/sonar-isis2603/
sonar.projectKey=${repo}:sonar
sonar.projectName=${repo}
sonar.projectVersion=1.0
sonar.sources=src/app
sonar.test=src/app
sonar.test.inclusions=**/*.spec.ts
sonar.exclusions=**/*.module.ts, **/utils/**
sonar.ts.tslint.configPath=tslint.json
sonar.javascript.lcov.reportPaths=coverage/front/lcov.info
sonar.testExecutionReportPaths=reports/ut_report.xml`;
return content;
}
function getJenkinsFile(repo) {
const content = `pipeline {
agent any
environment {
GIT_REPO = '${repo}'
GIT_CREDENTIAL_ID = 'de5cd571-10da-4034-8ba8-af99beef4b14'
SONARQUBE_URL = 'http://172.24.100.52:8082/sonar-isis2603'
}
stages {
stage('Checkout') {
steps {
scmSkip(deleteBuild: true, skipPattern:'.*\\\\[ci-skip\\\\].*')
git branch: 'master',
credentialsId: env.GIT_CREDENTIAL_ID,
url: 'https://github.com/Uniandes-isis2603/' + env.GIT_REPO
}
}
stage('Git Analysis') {
// Run git analysis
steps {
script {
docker.image('gitinspector-isis2603').inside('--entrypoint=""') {
sh '''
mkdir -p ./reports/
datetime=$(date +'%Y-%m-%d_%H%M%S')
gitinspector --file-types="cs,js,asax,ascx,asmx,aspx,html,fs,ts" --format=html --RxU -w -T -x author:Bocanegra -x author:estudiante > ./reports/index.html
'''
}
}
withCredentials([usernamePassword(credentialsId: env.GIT_CREDENTIAL_ID, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh('git config --global user.email "[email protected]"')
sh('git config --global user.name "ci-isis2603"')
sh('git add ./reports/index.html')
sh('git commit -m "[ci-skip] GitInspector report added"')
sh('git pull https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/Uniandes-isis2603/\${GIT_REPO} master')
sh('git push https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/Uniandes-isis2603/\${GIT_REPO} master')
}
}
}
stage('Build') {
// Build app
steps {
script {
docker.image('citools-isis2603:latest').inside('-u root') {
sh '''
npm i -s
npm i [email protected]
ng build
'''
}
}
}
}
stage('Test') {
steps {
script {
docker.image('citools-isis2603:latest').inside('-u root') {
sh '''
ng test --watch=false --code-coverage true
npm run sonar
'''
}
}
}
}
stage('Static Analysis') {
// Run static analysis
steps {
sh '''
docker run --rm -u root -e SONAR_HOST_URL=\${SONARQUBE_URL} -v \${WORKSPACE}:/usr/src sonarsource/sonar-scanner-cli:4.3
'''
}
}
}
post {
always {
// Clean workspace
cleanWs deleteDirs: true
}
}
}
`;
return content;
}