@docupace/pipeline 1.0.26 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/next/deploy.js +2 -1
- package/src/next/jenkins.js +123 -123
package/package.json
CHANGED
package/src/next/deploy.js
CHANGED
|
@@ -27,10 +27,11 @@ async function updateAndCommitConnectVersion(
|
|
|
27
27
|
getComparedVersion,
|
|
28
28
|
connectDeployPath,
|
|
29
29
|
) {
|
|
30
|
+
const connectToEnv = toEnv == 'qa' ? 'preprod' : toEnv;
|
|
30
31
|
const filePath = path.join(
|
|
31
32
|
connectDeployPath,
|
|
32
33
|
'envs',
|
|
33
|
-
|
|
34
|
+
connectToEnv,
|
|
34
35
|
toSite,
|
|
35
36
|
'dock.sh',
|
|
36
37
|
);
|
package/src/next/jenkins.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const CORE_JENKINS_URL = 'http://devops.corp.docupace.com';
|
|
4
|
-
const CORE_JOB_NAME = 'auto-deploy-site';
|
|
5
|
-
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
-
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
-
|
|
8
|
-
const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
|
|
9
|
-
const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
|
|
10
|
-
const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
|
|
11
|
-
const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
|
|
12
|
-
|
|
13
|
-
export async function deployCore(env, site, liquibase, gitBranch) {
|
|
14
|
-
const parameters = {
|
|
15
|
-
environment: env,
|
|
16
|
-
site: site.toUpperCase(),
|
|
17
|
-
runLiquibase: liquibase,
|
|
18
|
-
gitBranch,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return callJenkinsJob({
|
|
22
|
-
jenkinsUrl: CORE_JENKINS_URL,
|
|
23
|
-
jobName: CORE_JOB_NAME,
|
|
24
|
-
auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
|
|
25
|
-
parameters,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line no-unused-vars
|
|
30
|
-
export async function deployConnect(env, site, liquibase, branch) {
|
|
31
|
-
const parameters = {
|
|
32
|
-
BUILD_ENVIRONMENT: env,
|
|
33
|
-
BUILD_SITE: site,
|
|
34
|
-
RUN_LIQUIBASE: liquibase,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return callJenkinsJob({
|
|
38
|
-
jenkinsUrl: CONNECT_JENKINS_URL,
|
|
39
|
-
jobName: CONNECT_JOB_NAME,
|
|
40
|
-
auth: { username: CONNECT_USERNAME, password: CONNECT_API_TOKEN },
|
|
41
|
-
parameters,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function callJenkinsJob({
|
|
46
|
-
jenkinsUrl,
|
|
47
|
-
jobName,
|
|
48
|
-
auth,
|
|
49
|
-
parameters,
|
|
50
|
-
}) {
|
|
51
|
-
try {
|
|
52
|
-
// Trigger the job
|
|
53
|
-
console.log('Triggering Jenkins job...');
|
|
54
|
-
const buildResponse = await axios.post(
|
|
55
|
-
`${jenkinsUrl}/job/${jobName}/buildWithParameters`,
|
|
56
|
-
new URLSearchParams(parameters),
|
|
57
|
-
{
|
|
58
|
-
auth,
|
|
59
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
60
|
-
validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
|
|
61
|
-
},
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const queueUrl = buildResponse.headers.location;
|
|
65
|
-
console.log(`Job queued at: ${queueUrl}`);
|
|
66
|
-
|
|
67
|
-
// Poll queue for executable URL
|
|
68
|
-
let jobUrl = null;
|
|
69
|
-
while (!jobUrl) {
|
|
70
|
-
const queueResponse = await axios.get(`${queueUrl}api/json`, {
|
|
71
|
-
auth,
|
|
72
|
-
});
|
|
73
|
-
jobUrl = queueResponse.data.executable?.url || null;
|
|
74
|
-
|
|
75
|
-
if (!jobUrl) {
|
|
76
|
-
console.log('Waiting for job to start...');
|
|
77
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
jobUrl = jobUrl.replaceAll('https', 'http');
|
|
82
|
-
|
|
83
|
-
console.log(`Job started at: ${jobUrl}`);
|
|
84
|
-
|
|
85
|
-
// Stream console output
|
|
86
|
-
const consoleUrl = `${jobUrl}consoleText`;
|
|
87
|
-
let lastSize = 0;
|
|
88
|
-
|
|
89
|
-
console.log('Streaming job output...');
|
|
90
|
-
while (true) {
|
|
91
|
-
const consoleResponse = await axios.get(consoleUrl, {
|
|
92
|
-
auth,
|
|
93
|
-
responseType: 'text',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const consoleText = consoleResponse.data;
|
|
97
|
-
const newOutput = consoleText.slice(lastSize);
|
|
98
|
-
process.stdout.write(newOutput); // Write new output to console
|
|
99
|
-
lastSize = consoleText.length;
|
|
100
|
-
|
|
101
|
-
// Check job status
|
|
102
|
-
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
103
|
-
auth,
|
|
104
|
-
});
|
|
105
|
-
const result = jobResponse.data.result;
|
|
106
|
-
|
|
107
|
-
if (result) {
|
|
108
|
-
console.log(`\nJob completed with result: ${result}`);
|
|
109
|
-
if (result === 'SUCCESS') {
|
|
110
|
-
return;
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error('Jenkins job failed');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Wait before polling again
|
|
117
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
118
|
-
}
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error('Error:', error.message);
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const CORE_JENKINS_URL = 'http://devops.corp.docupace.com';
|
|
4
|
+
const CORE_JOB_NAME = 'auto-deploy-site';
|
|
5
|
+
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
+
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
+
|
|
8
|
+
const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
|
|
9
|
+
const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
|
|
10
|
+
const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
|
|
11
|
+
const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
|
|
12
|
+
|
|
13
|
+
export async function deployCore(env, site, liquibase, gitBranch) {
|
|
14
|
+
const parameters = {
|
|
15
|
+
environment: env,
|
|
16
|
+
site: site.toUpperCase(),
|
|
17
|
+
runLiquibase: liquibase,
|
|
18
|
+
gitBranch,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return callJenkinsJob({
|
|
22
|
+
jenkinsUrl: CORE_JENKINS_URL,
|
|
23
|
+
jobName: CORE_JOB_NAME,
|
|
24
|
+
auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
|
|
25
|
+
parameters,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line no-unused-vars
|
|
30
|
+
export async function deployConnect(env, site, liquibase, branch) {
|
|
31
|
+
const parameters = {
|
|
32
|
+
BUILD_ENVIRONMENT: env,
|
|
33
|
+
BUILD_SITE: site,
|
|
34
|
+
RUN_LIQUIBASE: liquibase,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return callJenkinsJob({
|
|
38
|
+
jenkinsUrl: CONNECT_JENKINS_URL,
|
|
39
|
+
jobName: CONNECT_JOB_NAME,
|
|
40
|
+
auth: { username: CONNECT_USERNAME, password: CONNECT_API_TOKEN },
|
|
41
|
+
parameters,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function callJenkinsJob({
|
|
46
|
+
jenkinsUrl,
|
|
47
|
+
jobName,
|
|
48
|
+
auth,
|
|
49
|
+
parameters,
|
|
50
|
+
}) {
|
|
51
|
+
try {
|
|
52
|
+
// Trigger the job
|
|
53
|
+
console.log('Triggering Jenkins job...');
|
|
54
|
+
const buildResponse = await axios.post(
|
|
55
|
+
`${jenkinsUrl}/job/${jobName}/buildWithParameters`,
|
|
56
|
+
new URLSearchParams(parameters),
|
|
57
|
+
{
|
|
58
|
+
auth,
|
|
59
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
60
|
+
validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const queueUrl = buildResponse.headers.location;
|
|
65
|
+
console.log(`Job queued at: ${queueUrl}`);
|
|
66
|
+
|
|
67
|
+
// Poll queue for executable URL
|
|
68
|
+
let jobUrl = null;
|
|
69
|
+
while (!jobUrl) {
|
|
70
|
+
const queueResponse = await axios.get(`${queueUrl}api/json`, {
|
|
71
|
+
auth,
|
|
72
|
+
});
|
|
73
|
+
jobUrl = queueResponse.data.executable?.url || null;
|
|
74
|
+
|
|
75
|
+
if (!jobUrl) {
|
|
76
|
+
console.log('Waiting for job to start...');
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
jobUrl = jobUrl.replaceAll('https', 'http');
|
|
82
|
+
|
|
83
|
+
console.log(`Job started at: ${jobUrl}`);
|
|
84
|
+
|
|
85
|
+
// Stream console output
|
|
86
|
+
const consoleUrl = `${jobUrl}consoleText`;
|
|
87
|
+
let lastSize = 0;
|
|
88
|
+
|
|
89
|
+
console.log('Streaming job output...');
|
|
90
|
+
while (true) {
|
|
91
|
+
const consoleResponse = await axios.get(consoleUrl, {
|
|
92
|
+
auth,
|
|
93
|
+
responseType: 'text',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const consoleText = consoleResponse.data;
|
|
97
|
+
const newOutput = consoleText.slice(lastSize);
|
|
98
|
+
process.stdout.write(newOutput); // Write new output to console
|
|
99
|
+
lastSize = consoleText.length;
|
|
100
|
+
|
|
101
|
+
// Check job status
|
|
102
|
+
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
103
|
+
auth,
|
|
104
|
+
});
|
|
105
|
+
const result = jobResponse.data.result;
|
|
106
|
+
|
|
107
|
+
if (result) {
|
|
108
|
+
console.log(`\nJob completed with result: ${result}`);
|
|
109
|
+
if (result === 'SUCCESS') {
|
|
110
|
+
return;
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error('Jenkins job failed');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Wait before polling again
|
|
117
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error('Error:', error.message);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|