@docupace/pipeline 1.0.54 → 1.0.56
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/README.md +135 -135
- package/bin/azuread_update_callbacks_for_app.sh +58 -58
- package/bin/next-changeset-validate.sh +8 -8
- package/eslint.config.js +26 -26
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +123 -123
- package/next/sonar.sh +23 -23
- package/package.json +50 -50
- package/src/auth0/alias.js +72 -72
- package/src/auth0/cli.js +0 -0
- package/src/auth0/export.js +43 -43
- package/src/auth0/metadata.js +132 -132
- package/src/auth0/vault.js +107 -107
- package/src/changeset/changeset-config.js +34 -34
- package/src/changeset/cli.js +200 -200
- package/src/changeset/create.js +205 -205
- package/src/changeset/package-util.js +86 -86
- package/src/changeset/util.js +43 -43
- package/src/changeset/validate.js +84 -84
- package/src/changeset/version.js +102 -102
- package/src/jenkins/setParams.groovy +58 -58
- package/src/next/alias.js +53 -53
- package/src/next/apache.js +81 -73
- package/src/next/cli.js +228 -228
- package/src/next/config.js +137 -136
- package/src/next/connect.js +227 -227
- package/src/next/copy.js +61 -61
- package/src/next/deploy.js +595 -595
- package/src/next/haproxy.js +75 -71
- package/src/next/jira.js +84 -84
- package/src/next/logger.js +17 -17
- package/src/next/pipline.js +114 -114
- package/src/next/publish.js +71 -71
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/src/next/util.js +93 -93
- package/src/next/vault.js +45 -45
- package/terraform/apply.sh +37 -37
- package/terraform/init.sh +72 -72
- package/terraform/plan.sh +76 -76
- package/terraform/validate.sh +17 -17
package/src/next/haproxy.js
CHANGED
|
@@ -1,71 +1,75 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
export async function haproxySync() {
|
|
6
|
-
const cluster = process.env.HAPROXY_CLUSTER;
|
|
7
|
-
if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
|
|
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: '
|
|
24
|
-
},
|
|
25
|
-
'prod-
|
|
26
|
-
host: '10.13.28.
|
|
27
|
-
branch: '
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
git
|
|
42
|
-
git
|
|
43
|
-
git
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
1
|
+
import { $ } from 'zx';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export async function haproxySync() {
|
|
6
|
+
const cluster = process.env.HAPROXY_CLUSTER;
|
|
7
|
+
if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
|
|
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: 'master',
|
|
24
|
+
},
|
|
25
|
+
'prod-www2': {
|
|
26
|
+
host: ' 10.13.28.43',
|
|
27
|
+
branch: 'master',
|
|
28
|
+
},
|
|
29
|
+
'prod-www3': {
|
|
30
|
+
host: '10.13.28.45',
|
|
31
|
+
branch: 'master',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const scriptContent = `
|
|
36
|
+
#!/bin/bash
|
|
37
|
+
|
|
38
|
+
[[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
|
|
39
|
+
cd ${repoPath}
|
|
40
|
+
pwd
|
|
41
|
+
git stash
|
|
42
|
+
git fetch --all
|
|
43
|
+
git pull origin master
|
|
44
|
+
git checkout ${cluserHostMap[cluster].branch}
|
|
45
|
+
git submodule update --remote
|
|
46
|
+
git submodule foreach --recursive git checkout master
|
|
47
|
+
git submodule foreach --recursive git pull origin master
|
|
48
|
+
|
|
49
|
+
ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
|
|
50
|
+
|
|
51
|
+
echo "proceeding"
|
|
52
|
+
echo "committing changes"
|
|
53
|
+
git add ${cluster}-haproxy.cfg
|
|
54
|
+
git commit -m "Sync haproxy"
|
|
55
|
+
git push origin master
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
await fs.writeFile('haproxy.sh', scriptContent);
|
|
59
|
+
|
|
60
|
+
// Private key
|
|
61
|
+
const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
|
|
62
|
+
if (!haproxyPrivateKey) {
|
|
63
|
+
console.log('Error: HAPROXY_PRIVATE_KEY not set.');
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
68
|
+
await fs.chmod('private.key', 0o600);
|
|
69
|
+
|
|
70
|
+
// Copy script to remote
|
|
71
|
+
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
|
|
72
|
+
|
|
73
|
+
// Execute script on remote
|
|
74
|
+
await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
|
|
75
|
+
}
|
package/src/next/jira.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
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
|
-
/**
|
|
16
|
-
* Updates the component version custom field in Jira
|
|
17
|
-
* @param {string} issueKey - The Jira issue key
|
|
18
|
-
* @param {string} packageName - The package name
|
|
19
|
-
* @param {string} version - The version to set
|
|
20
|
-
*/
|
|
21
|
-
export async function updateComponentVersion(issueKey, packageName, version) {
|
|
22
|
-
const component = packageName.includes('/')
|
|
23
|
-
? packageName.split('/')[1]
|
|
24
|
-
: packageName;
|
|
25
|
-
console.log(
|
|
26
|
-
`Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
|
|
27
|
-
);
|
|
28
|
-
try {
|
|
29
|
-
// First get current field value
|
|
30
|
-
const response = await jiraClient.get(
|
|
31
|
-
`/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
let currentValue = response.data.fields.customfield_10458 || '';
|
|
35
|
-
let components = new Map();
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
// Parse existing components
|
|
39
|
-
if (currentValue) {
|
|
40
|
-
currentValue.split(';').forEach((entry) => {
|
|
41
|
-
const [comp, ver] = entry.split(':');
|
|
42
|
-
components.set(comp, ver);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
// Update or add new component version
|
|
46
|
-
} catch {
|
|
47
|
-
console.log('Patch version has incorrect data overriding');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
components.set(component, version);
|
|
51
|
-
|
|
52
|
-
// Convert back to string format
|
|
53
|
-
const newValue = Array.from(components.entries())
|
|
54
|
-
.map(([comp, ver]) => `${comp}:${ver}`)
|
|
55
|
-
.join(';');
|
|
56
|
-
|
|
57
|
-
// Update the field
|
|
58
|
-
await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
|
|
59
|
-
fields: {
|
|
60
|
-
customfield_10458: newValue,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
console.log(`Updated component versions for ${issueKey}: ${newValue}`);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error(`Error updating Jira component version: ${error.message}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Makes a request to the Jira API using preconfigured client
|
|
72
|
-
* @param {string} endpoint - The API endpoint (starting with /)
|
|
73
|
-
* @param {Object} options - Request options (method, body, etc)
|
|
74
|
-
* @returns {Promise<any>} The response data
|
|
75
|
-
*/
|
|
76
|
-
export async function makeJiraRequest(endpoint, options = {}) {
|
|
77
|
-
try {
|
|
78
|
-
const response = await jiraClient.get(endpoint, options);
|
|
79
|
-
return response.data;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error(`Error making Jira request: ${error.message}`);
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
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
|
+
/**
|
|
16
|
+
* Updates the component version custom field in Jira
|
|
17
|
+
* @param {string} issueKey - The Jira issue key
|
|
18
|
+
* @param {string} packageName - The package name
|
|
19
|
+
* @param {string} version - The version to set
|
|
20
|
+
*/
|
|
21
|
+
export async function updateComponentVersion(issueKey, packageName, version) {
|
|
22
|
+
const component = packageName.includes('/')
|
|
23
|
+
? packageName.split('/')[1]
|
|
24
|
+
: packageName;
|
|
25
|
+
console.log(
|
|
26
|
+
`Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
|
|
27
|
+
);
|
|
28
|
+
try {
|
|
29
|
+
// First get current field value
|
|
30
|
+
const response = await jiraClient.get(
|
|
31
|
+
`/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
let currentValue = response.data.fields.customfield_10458 || '';
|
|
35
|
+
let components = new Map();
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Parse existing components
|
|
39
|
+
if (currentValue) {
|
|
40
|
+
currentValue.split(';').forEach((entry) => {
|
|
41
|
+
const [comp, ver] = entry.split(':');
|
|
42
|
+
components.set(comp, ver);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Update or add new component version
|
|
46
|
+
} catch {
|
|
47
|
+
console.log('Patch version has incorrect data overriding');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
components.set(component, version);
|
|
51
|
+
|
|
52
|
+
// Convert back to string format
|
|
53
|
+
const newValue = Array.from(components.entries())
|
|
54
|
+
.map(([comp, ver]) => `${comp}:${ver}`)
|
|
55
|
+
.join(';');
|
|
56
|
+
|
|
57
|
+
// Update the field
|
|
58
|
+
await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
|
|
59
|
+
fields: {
|
|
60
|
+
customfield_10458: newValue,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log(`Updated component versions for ${issueKey}: ${newValue}`);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(`Error updating Jira component version: ${error.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Makes a request to the Jira API using preconfigured client
|
|
72
|
+
* @param {string} endpoint - The API endpoint (starting with /)
|
|
73
|
+
* @param {Object} options - Request options (method, body, etc)
|
|
74
|
+
* @returns {Promise<any>} The response data
|
|
75
|
+
*/
|
|
76
|
+
export async function makeJiraRequest(endpoint, options = {}) {
|
|
77
|
+
try {
|
|
78
|
+
const response = await jiraClient.get(endpoint, options);
|
|
79
|
+
return response.data;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(`Error making Jira request: ${error.message}`);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/next/logger.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { $ as original$ } from 'zx';
|
|
2
|
-
|
|
3
|
-
// Wrapped version of $
|
|
4
|
-
export const $ = async (strings, ...values) => {
|
|
5
|
-
const command = strings.reduce(
|
|
6
|
-
(acc, str, i) => acc + str + (values[i] ?? ''),
|
|
7
|
-
'',
|
|
8
|
-
);
|
|
9
|
-
console.log(`Executing: ${command}`);
|
|
10
|
-
try {
|
|
11
|
-
const result = await original$(strings, ...values);
|
|
12
|
-
return result;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
console.error(`Error executing: ${command}`, error);
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
1
|
+
import { $ as original$ } from 'zx';
|
|
2
|
+
|
|
3
|
+
// Wrapped version of $
|
|
4
|
+
export const $ = async (strings, ...values) => {
|
|
5
|
+
const command = strings.reduce(
|
|
6
|
+
(acc, str, i) => acc + str + (values[i] ?? ''),
|
|
7
|
+
'',
|
|
8
|
+
);
|
|
9
|
+
console.log(`Executing: ${command}`);
|
|
10
|
+
try {
|
|
11
|
+
const result = await original$(strings, ...values);
|
|
12
|
+
return result;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(`Error executing: ${command}`, error);
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
};
|
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
|
+
}
|