@docupace/pipeline 1.0.5 → 1.0.6-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.5",
3
+ "version": "1.0.6-alpha.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/next/cli.js CHANGED
@@ -16,7 +16,7 @@ const program = new Command();
16
16
  // GIT SHA computation
17
17
  import { $ } from 'zx';
18
18
  import { deployCore } from './jenkins.js';
19
- import { runPipeline } from './pipline.js';
19
+ import {runPipeline, triggerPipelineByName} from './pipline.js';
20
20
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
21
21
 
22
22
  program
@@ -95,4 +95,34 @@ program
95
95
  await copy(application, fromEnv, toEnv, tag);
96
96
  });
97
97
 
98
+ program
99
+ .command('trigger-pipeline')
100
+ .description('Trigger a pipeline by name')
101
+ .requiredOption('-r, --repository <repository>', 'Repository name')
102
+ .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
103
+ .requiredOption('-b, --branch <branch>', 'Branch name')
104
+ .option(
105
+ '-v, --variables <key=value>',
106
+ 'Pipeline variable as key=value pair',
107
+ (value, previous) => {
108
+ const [key, val] = value.split('=');
109
+ if (!key || val === undefined) {
110
+ throw new Error(`Invalid variable format: ${value}. Use key=value.`);
111
+ }
112
+ return { ...previous, [key]: val };
113
+ },
114
+ {},
115
+ ) // Initialize as an empty object
116
+ .action(async (cmdObj) => {
117
+ try {
118
+ const { repository, pipelineName, branch, variables } = cmdObj;
119
+
120
+ // Call the triggerPipelineByName function
121
+ await triggerPipelineByName(repository, pipelineName, branch, variables);
122
+ } catch (error) {
123
+ console.error('Error triggering pipeline:', error.message);
124
+ process.exit(1);
125
+ }
126
+ });
127
+
98
128
  program.parse(process.argv);
@@ -3,7 +3,7 @@ import { getBitbucketInfo } from './config.js';
3
3
 
4
4
  const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
5
5
 
6
- async function triggerPipelineByName(
6
+ export async function triggerPipelineByName(
7
7
  repository,
8
8
  pipelineName,
9
9
  branch,
@@ -26,11 +26,13 @@ async function triggerPipelineByName(
26
26
  pattern: pipelineName,
27
27
  },
28
28
  },
29
- variables: Object.entries(variables).map(([key, value]) => ({
30
- key,
31
- value,
32
- secured: false, // Set to true if the variable should be secure
33
- })),
29
+ variables: variables
30
+ ? Object.entries(variables).map(([key, value]) => ({
31
+ key,
32
+ value,
33
+ secured: false, // Set to true if the variable should be secure
34
+ }))
35
+ : undefined,
34
36
  };
35
37
 
36
38
  try {