@docupace/pipeline 1.0.3-1.demo1 → 1.0.4-1.haproxysync.1
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/.prettierrc.cjs +12 -12
- package/bin/next-changeset-validate.sh +8 -8
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +117 -117
- package/next/sonar.sh +23 -23
- package/package.json +3 -2
- package/src/auth0/alias.js +72 -75
- package/src/auth0/cli.js +76 -41
- package/src/auth0/configure.js +783 -715
- package/src/auth0/export.js +43 -0
- package/src/auth0/metadata.js +132 -0
- package/src/auth0/vault.js +107 -107
- package/src/changeset/cli.js +334 -324
- package/src/changeset/validate.js +47 -47
- package/src/jenkins/setParams.groovy +59 -59
- package/src/next/alias.js +53 -53
- package/src/next/apache.js +40 -64
- package/src/next/cli.js +29 -4
- package/src/next/config.js +99 -84
- package/src/next/copy.js +55 -52
- package/src/next/deploy.js +16 -8
- package/src/next/haproxy.js +45 -29
- package/src/next/jira.js +83 -86
- package/src/next/pipline.js +114 -114
- package/src/next/publish.js +48 -48
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/src/next/vault.js +43 -43
- package/terraform/apply.sh +26 -26
- package/terraform/init.sh +61 -48
- package/terraform/plan.sh +63 -54
- package/terraform/validate.sh +17 -17
package/src/next/copy.js
CHANGED
|
@@ -1,52 +1,55 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
|
-
import { appInfo, getEnvInfo, jfRegistryUrl } from './config.js';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
TARGET_ENV
|
|
6
|
-
PUBLISH_TAG
|
|
7
|
-
REPOSITORY_NAME
|
|
8
|
-
*/
|
|
9
|
-
export async function copy(application, fromEnv, toEnv, tag) {
|
|
10
|
-
const envInfo = getEnvInfo();
|
|
11
|
-
const repositoryName = appInfo[application].repositoryName;
|
|
12
|
-
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
13
|
-
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
14
|
-
const imageName = `${repositoryName}:${tag}`;
|
|
15
|
-
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
16
|
-
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
17
|
-
|
|
18
|
-
console.log(
|
|
19
|
-
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
// Login to source registry
|
|
23
|
-
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
24
|
-
await $`docker pull ${fromFullImageName}`;
|
|
25
|
-
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
26
|
-
|
|
27
|
-
// Login to target registry
|
|
28
|
-
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
29
|
-
await $`docker push ${toFullImageName}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function copy2(repositoryName, fromEnv, toEnv, tag) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await $`
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
import { $ } from 'zx';
|
|
2
|
+
import { appInfo, getEnvInfo, jfRegistryUrl } from './config.js';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
TARGET_ENV
|
|
6
|
+
PUBLISH_TAG
|
|
7
|
+
REPOSITORY_NAME
|
|
8
|
+
*/
|
|
9
|
+
export async function copy(application, fromEnv, toEnv, tag) {
|
|
10
|
+
const envInfo = getEnvInfo();
|
|
11
|
+
const repositoryName = appInfo[application].repositoryName;
|
|
12
|
+
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
13
|
+
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
14
|
+
const imageName = `${repositoryName}:${tag}`;
|
|
15
|
+
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
16
|
+
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
17
|
+
|
|
18
|
+
console.log(
|
|
19
|
+
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Login to source registry
|
|
23
|
+
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
24
|
+
await $`docker pull ${fromFullImageName}`;
|
|
25
|
+
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
26
|
+
|
|
27
|
+
// Login to target registry
|
|
28
|
+
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
29
|
+
await $`docker push ${toFullImageName}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function copy2(repositoryName, fromEnv, toEnv, tag) {
|
|
33
|
+
console.log(
|
|
34
|
+
`Copying repository ${repositoryName} from ${fromEnv} to ${toEnv} for tag ${tag}`,
|
|
35
|
+
);
|
|
36
|
+
const envInfo = getEnvInfo();
|
|
37
|
+
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
38
|
+
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
39
|
+
const imageName = `${repositoryName}:${tag}`;
|
|
40
|
+
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
41
|
+
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
42
|
+
|
|
43
|
+
console.log(
|
|
44
|
+
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Login to source registry
|
|
48
|
+
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
49
|
+
await $`docker pull ${fromFullImageName}`;
|
|
50
|
+
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
51
|
+
|
|
52
|
+
// Login to target registry
|
|
53
|
+
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
54
|
+
await $`docker push ${toFullImageName}`;
|
|
55
|
+
}
|
package/src/next/deploy.js
CHANGED
|
@@ -266,7 +266,7 @@ export async function writeAndPushDeployConfig(
|
|
|
266
266
|
* @param {string} site - The site name.
|
|
267
267
|
*/
|
|
268
268
|
|
|
269
|
-
async function getDeployTag() {
|
|
269
|
+
export async function getDeployTag() {
|
|
270
270
|
const gitTag = (
|
|
271
271
|
await $`git tag --points-at HEAD | grep '^v' | head -n 1`
|
|
272
272
|
).stdout.trim();
|
|
@@ -274,12 +274,17 @@ async function getDeployTag() {
|
|
|
274
274
|
return deployTag;
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
export async function
|
|
278
|
-
const
|
|
277
|
+
export async function getDefaultDeploySite(deployTag) {
|
|
278
|
+
const env = deployTag.includes('alpha') ? 'dev' : 'qa';
|
|
279
|
+
const site = env === 'dev' ? 'financialdev' : 'qa';
|
|
280
|
+
return { env, site };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function deployTemplate(env, site, deployTag) {
|
|
279
284
|
console.log(`Deploying standard template for site: ${site}`);
|
|
280
285
|
console.log(`Using deployment tag: ${deployTag}`);
|
|
281
286
|
const { repoPath, deployConfigFilePath, deployConfig } =
|
|
282
|
-
await cloneAndReadDeployConfig('graphql-server',
|
|
287
|
+
await cloneAndReadDeployConfig('graphql-server', env, site);
|
|
283
288
|
|
|
284
289
|
deployConfig.graphqlServer.standardConfigRemoteBranch = deployTag;
|
|
285
290
|
|
|
@@ -292,14 +297,17 @@ export async function deployTemplate(site) {
|
|
|
292
297
|
console.log('Deployment completed successfully.');
|
|
293
298
|
}
|
|
294
299
|
|
|
295
|
-
export async function
|
|
296
|
-
const deployTag = getDeployTag();
|
|
297
|
-
|
|
300
|
+
export async function deployAppWithTag(application, env, site, deployTag) {
|
|
298
301
|
console.log(`Deploying application: ${application} for site: ${site}`);
|
|
299
302
|
console.log(`Using deployment tag: ${deployTag}`);
|
|
300
303
|
|
|
304
|
+
if (env !== 'dev') {
|
|
305
|
+
const appDetails = appInfo[application];
|
|
306
|
+
await copy2(appDetails.repositoryName, 'dev', env, deployTag);
|
|
307
|
+
}
|
|
308
|
+
|
|
301
309
|
const { repoPath, deployConfigFilePath, deployConfig } =
|
|
302
|
-
await cloneAndReadDeployConfig(application,
|
|
310
|
+
await cloneAndReadDeployConfig(application, env, site);
|
|
303
311
|
const updatedConfigData = setTag(deployConfig, deployTag);
|
|
304
312
|
await writeAndPushDeployConfig(
|
|
305
313
|
repoPath,
|
package/src/next/haproxy.js
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import { $ } from 'zx';
|
|
2
|
-
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
3
4
|
|
|
4
5
|
export async function haproxySync() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const cluster = process.env.HAPROXY_CLUSTER;
|
|
7
|
+
if (cluster !== 'preprod' && cluster !== 'stage') {
|
|
8
|
+
console.log('Error: Cluster must be preprod or stage');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const repoPath = '/root/repo/docupace-ansible';
|
|
13
|
+
const inventory = path.join(repoPath, `inventories/${cluster}/inventory`);
|
|
14
|
+
|
|
15
|
+
// Create haproxy.sh
|
|
16
|
+
const cluserHostMap = {
|
|
17
|
+
preprod: {
|
|
18
|
+
host: '10.10.28.198',
|
|
19
|
+
branch: 'master',
|
|
20
|
+
},
|
|
21
|
+
stage: {
|
|
22
|
+
host: '10.12.28.10',
|
|
23
|
+
branch: 'INFP-6565-haproxy-prod-implementation',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const scriptContent = `
|
|
10
28
|
#!/bin/bash
|
|
11
29
|
|
|
12
30
|
[[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
|
|
@@ -14,37 +32,35 @@ export async function haproxySync() {
|
|
|
14
32
|
pwd
|
|
15
33
|
git stash
|
|
16
34
|
git pull origin master
|
|
17
|
-
git checkout
|
|
35
|
+
git checkout ${cluserHostMap[cluster].branch}
|
|
18
36
|
git submodule update --remote
|
|
19
37
|
git submodule foreach --recursive git checkout master
|
|
20
38
|
git submodule foreach --recursive git pull origin master
|
|
21
39
|
|
|
22
|
-
ansible-playbook -i inventories/
|
|
40
|
+
ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster}"
|
|
23
41
|
|
|
24
42
|
echo "proceeding"
|
|
25
43
|
echo "committing changes"
|
|
26
|
-
git add
|
|
44
|
+
git add ${cluster}-haproxy.cfg
|
|
27
45
|
git commit -m "Sync haproxy"
|
|
28
46
|
git push origin master
|
|
29
47
|
`;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
41
|
-
await fs.chmod('private.key', 0o600);
|
|
42
|
-
|
|
43
|
-
await $`cat private.key`; // Just to mimic the script's behavior
|
|
44
|
-
|
|
45
|
-
// Copy script to remote
|
|
46
|
-
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@10.10.28.198:/tmp/haproxy.sh`;
|
|
47
|
-
|
|
48
|
-
// Execute script on remote
|
|
49
|
-
await $`ssh -i private.key -o StrictHostKeyChecking=no root@10.10.28.198 "bash /tmp/haproxy.sh"`;
|
|
48
|
+
|
|
49
|
+
await fs.writeFile('haproxy.sh', scriptContent);
|
|
50
|
+
|
|
51
|
+
// Private key
|
|
52
|
+
const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
|
|
53
|
+
if (!haproxyPrivateKey) {
|
|
54
|
+
console.log('Error: HAPROXY_PRIVATE_KEY not set.');
|
|
55
|
+
process.exit(1);
|
|
50
56
|
}
|
|
57
|
+
|
|
58
|
+
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
59
|
+
await fs.chmod('private.key', 0o600);
|
|
60
|
+
|
|
61
|
+
// Copy script to remote
|
|
62
|
+
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
|
|
63
|
+
|
|
64
|
+
// Execute script on remote
|
|
65
|
+
await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
|
|
66
|
+
}
|
package/src/next/jira.js
CHANGED
|
@@ -1,86 +1,83 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
// Create preconfigured axios instance for Jira
|
|
4
|
-
const jiraClient = axios.create({
|
|
5
|
-
baseURL: 'https://docupacellc.atlassian.net',
|
|
6
|
-
auth: {
|
|
7
|
-
username: process.env.JIRA_API_EMAIL,
|
|
8
|
-
password: process.env.JIRA_API_KEY,
|
|
9
|
-
},
|
|
10
|
-
headers: {
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const packageComponents = {
|
|
16
|
-
'docupace-ui': 'next-ui',
|
|
17
|
-
'docupace-graphql-server': 'graphql-server',
|
|
18
|
-
template: 'template',
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Updates the component version custom field in Jira
|
|
22
|
-
* @param {string} issueKey - The Jira issue key
|
|
23
|
-
* @param {string} component - The component name
|
|
24
|
-
* @param {string} version - The version to set
|
|
25
|
-
*/
|
|
26
|
-
export async function updateComponentVersion(issueKey, packageName, version) {
|
|
27
|
-
const component = packageComponents[packageName] ?? packageName;
|
|
28
|
-
console.log(
|
|
29
|
-
`Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
|
|
30
|
-
);
|
|
31
|
-
try {
|
|
32
|
-
// First get current field value
|
|
33
|
-
const response = await jiraClient.get(
|
|
34
|
-
`/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
let currentValue = response.data.fields.customfield_10458 || '';
|
|
38
|
-
let components = new Map();
|
|
39
|
-
|
|
40
|
-
// Parse existing components
|
|
41
|
-
if (currentValue) {
|
|
42
|
-
currentValue.split(';').forEach((entry) => {
|
|
43
|
-
const [comp, ver] = entry.split(':');
|
|
44
|
-
components.set(comp, ver);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Update or add new component version
|
|
49
|
-
components.set(component, version);
|
|
50
|
-
|
|
51
|
-
// Convert back to string format
|
|
52
|
-
const newValue = Array.from(components.entries())
|
|
53
|
-
.map(([comp, ver]) => `${comp}:${ver}`)
|
|
54
|
-
.join(';');
|
|
55
|
-
|
|
56
|
-
// Update the field
|
|
57
|
-
await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
|
|
58
|
-
fields: {
|
|
59
|
-
customfield_10458: newValue,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
console.log(`Updated component versions for ${issueKey}: ${newValue}`);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error(`Error updating Jira component version: ${error.message}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Makes a request to the Jira API using preconfigured client
|
|
71
|
-
* @param {string} endpoint - The API endpoint (starting with /)
|
|
72
|
-
* @param {Object} options - Request options (method, body, etc)
|
|
73
|
-
* @returns {Promise<any>} The response data
|
|
74
|
-
*/
|
|
75
|
-
export async function makeJiraRequest(endpoint, options = {}) {
|
|
76
|
-
try {
|
|
77
|
-
const response = await jiraClient(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
// Create preconfigured axios instance for Jira
|
|
4
|
+
const jiraClient = axios.create({
|
|
5
|
+
baseURL: 'https://docupacellc.atlassian.net',
|
|
6
|
+
auth: {
|
|
7
|
+
username: process.env.JIRA_API_EMAIL,
|
|
8
|
+
password: process.env.JIRA_API_KEY,
|
|
9
|
+
},
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const packageComponents = {
|
|
16
|
+
'docupace-ui': 'next-ui',
|
|
17
|
+
'docupace-graphql-server': 'graphql-server',
|
|
18
|
+
'@docupace/template': 'template',
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Updates the component version custom field in Jira
|
|
22
|
+
* @param {string} issueKey - The Jira issue key
|
|
23
|
+
* @param {string} component - The component name
|
|
24
|
+
* @param {string} version - The version to set
|
|
25
|
+
*/
|
|
26
|
+
export async function updateComponentVersion(issueKey, packageName, version) {
|
|
27
|
+
const component = packageComponents[packageName] ?? packageName;
|
|
28
|
+
console.log(
|
|
29
|
+
`Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
|
|
30
|
+
);
|
|
31
|
+
try {
|
|
32
|
+
// First get current field value
|
|
33
|
+
const response = await jiraClient.get(
|
|
34
|
+
`/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
let currentValue = response.data.fields.customfield_10458 || '';
|
|
38
|
+
let components = new Map();
|
|
39
|
+
|
|
40
|
+
// Parse existing components
|
|
41
|
+
if (currentValue) {
|
|
42
|
+
currentValue.split(';').forEach((entry) => {
|
|
43
|
+
const [comp, ver] = entry.split(':');
|
|
44
|
+
components.set(comp, ver);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Update or add new component version
|
|
49
|
+
components.set(component, version);
|
|
50
|
+
|
|
51
|
+
// Convert back to string format
|
|
52
|
+
const newValue = Array.from(components.entries())
|
|
53
|
+
.map(([comp, ver]) => `${comp}:${ver}`)
|
|
54
|
+
.join(';');
|
|
55
|
+
|
|
56
|
+
// Update the field
|
|
57
|
+
await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
|
|
58
|
+
fields: {
|
|
59
|
+
customfield_10458: newValue,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
console.log(`Updated component versions for ${issueKey}: ${newValue}`);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(`Error updating Jira component version: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Makes a request to the Jira API using preconfigured client
|
|
71
|
+
* @param {string} endpoint - The API endpoint (starting with /)
|
|
72
|
+
* @param {Object} options - Request options (method, body, etc)
|
|
73
|
+
* @returns {Promise<any>} The response data
|
|
74
|
+
*/
|
|
75
|
+
export async function makeJiraRequest(endpoint, options = {}) {
|
|
76
|
+
try {
|
|
77
|
+
const response = await jiraClient.get(endpoint, options);
|
|
78
|
+
return response.data;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(`Error making Jira request: ${error.message}`);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/next/pipline.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { getBitbucketInfo } from './config.js';
|
|
3
|
-
|
|
4
|
-
const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
|
|
5
|
-
|
|
6
|
-
const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
|
|
7
|
-
|
|
8
|
-
async function triggerPipelineByName(
|
|
9
|
-
repository,
|
|
10
|
-
pipelineName,
|
|
11
|
-
branch,
|
|
12
|
-
variables,
|
|
13
|
-
) {
|
|
14
|
-
const { username, password, workspace } = getBitbucketInfo();
|
|
15
|
-
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
|
|
16
|
-
const auth = {
|
|
17
|
-
username: username,
|
|
18
|
-
password: password,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const payload = {
|
|
22
|
-
target: {
|
|
23
|
-
type: 'pipeline_ref_target',
|
|
24
|
-
ref_type: 'branch',
|
|
25
|
-
ref_name: branch,
|
|
26
|
-
selector: {
|
|
27
|
-
type: 'custom',
|
|
28
|
-
pattern: pipelineName,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
variables: variables
|
|
32
|
-
? Object.entries(variables).map(([key, value]) => ({
|
|
33
|
-
key,
|
|
34
|
-
value,
|
|
35
|
-
secured: false, // Set to true if the variable should be secure
|
|
36
|
-
}))
|
|
37
|
-
: undefined,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const response = await axios.post(url, payload, { auth });
|
|
42
|
-
return response.data;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(
|
|
45
|
-
'Error triggering custom pipeline:',
|
|
46
|
-
error.response?.data || error.message,
|
|
47
|
-
);
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function getPipelineStatus(repository, pipelineUUID) {
|
|
53
|
-
const { username, password, workspace } = getBitbucketInfo();
|
|
54
|
-
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
|
|
55
|
-
const auth = {
|
|
56
|
-
username: username,
|
|
57
|
-
password: password,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const response = await axios.get(url, { auth });
|
|
62
|
-
return response.data.state.name;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error(
|
|
65
|
-
'Error fetching pipeline status:',
|
|
66
|
-
error.response?.data || error.message,
|
|
67
|
-
);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function runPipeline(
|
|
73
|
-
repository,
|
|
74
|
-
pipelineName,
|
|
75
|
-
branch,
|
|
76
|
-
variables,
|
|
77
|
-
wait = false,
|
|
78
|
-
) {
|
|
79
|
-
try {
|
|
80
|
-
console.log(
|
|
81
|
-
`Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
|
|
82
|
-
);
|
|
83
|
-
const pipeline = await triggerPipelineByName(
|
|
84
|
-
repository,
|
|
85
|
-
pipelineName,
|
|
86
|
-
branch,
|
|
87
|
-
variables,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const pipelineUUID = pipeline.uuid;
|
|
91
|
-
const buildNumber = pipeline.build_number;
|
|
92
|
-
|
|
93
|
-
console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
|
|
94
|
-
console.log(
|
|
95
|
-
`See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (!wait) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let status = '';
|
|
103
|
-
do {
|
|
104
|
-
console.log('Checking pipeline status...');
|
|
105
|
-
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
|
|
106
|
-
status = await getPipelineStatus(repository, pipelineUUID);
|
|
107
|
-
console.log(`Pipeline status: ${status}`);
|
|
108
|
-
} while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
|
|
109
|
-
|
|
110
|
-
console.log(`Pipeline completed with status: ${status}`);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error('Error monitoring pipeline:', error.message);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getBitbucketInfo } from './config.js';
|
|
3
|
+
|
|
4
|
+
const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
|
|
5
|
+
|
|
6
|
+
const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
|
|
7
|
+
|
|
8
|
+
async function triggerPipelineByName(
|
|
9
|
+
repository,
|
|
10
|
+
pipelineName,
|
|
11
|
+
branch,
|
|
12
|
+
variables,
|
|
13
|
+
) {
|
|
14
|
+
const { username, password, workspace } = getBitbucketInfo();
|
|
15
|
+
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
|
|
16
|
+
const auth = {
|
|
17
|
+
username: username,
|
|
18
|
+
password: password,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const payload = {
|
|
22
|
+
target: {
|
|
23
|
+
type: 'pipeline_ref_target',
|
|
24
|
+
ref_type: 'branch',
|
|
25
|
+
ref_name: branch,
|
|
26
|
+
selector: {
|
|
27
|
+
type: 'custom',
|
|
28
|
+
pattern: pipelineName,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
variables: variables
|
|
32
|
+
? Object.entries(variables).map(([key, value]) => ({
|
|
33
|
+
key,
|
|
34
|
+
value,
|
|
35
|
+
secured: false, // Set to true if the variable should be secure
|
|
36
|
+
}))
|
|
37
|
+
: undefined,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const response = await axios.post(url, payload, { auth });
|
|
42
|
+
return response.data;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(
|
|
45
|
+
'Error triggering custom pipeline:',
|
|
46
|
+
error.response?.data || error.message,
|
|
47
|
+
);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function getPipelineStatus(repository, pipelineUUID) {
|
|
53
|
+
const { username, password, workspace } = getBitbucketInfo();
|
|
54
|
+
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
|
|
55
|
+
const auth = {
|
|
56
|
+
username: username,
|
|
57
|
+
password: password,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const response = await axios.get(url, { auth });
|
|
62
|
+
return response.data.state.name;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(
|
|
65
|
+
'Error fetching pipeline status:',
|
|
66
|
+
error.response?.data || error.message,
|
|
67
|
+
);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function runPipeline(
|
|
73
|
+
repository,
|
|
74
|
+
pipelineName,
|
|
75
|
+
branch,
|
|
76
|
+
variables,
|
|
77
|
+
wait = false,
|
|
78
|
+
) {
|
|
79
|
+
try {
|
|
80
|
+
console.log(
|
|
81
|
+
`Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
|
|
82
|
+
);
|
|
83
|
+
const pipeline = await triggerPipelineByName(
|
|
84
|
+
repository,
|
|
85
|
+
pipelineName,
|
|
86
|
+
branch,
|
|
87
|
+
variables,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const pipelineUUID = pipeline.uuid;
|
|
91
|
+
const buildNumber = pipeline.build_number;
|
|
92
|
+
|
|
93
|
+
console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
|
|
94
|
+
console.log(
|
|
95
|
+
`See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (!wait) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let status = '';
|
|
103
|
+
do {
|
|
104
|
+
console.log('Checking pipeline status...');
|
|
105
|
+
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
|
|
106
|
+
status = await getPipelineStatus(repository, pipelineUUID);
|
|
107
|
+
console.log(`Pipeline status: ${status}`);
|
|
108
|
+
} while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
|
|
109
|
+
|
|
110
|
+
console.log(`Pipeline completed with status: ${status}`);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Error monitoring pipeline:', error.message);
|
|
113
|
+
}
|
|
114
|
+
}
|