@taole/deploy-helper 0.3.4 → 0.3.5

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/index.mjs CHANGED
@@ -5,7 +5,7 @@ import fs from 'fs';
5
5
  import { join, basename, dirname } from "path";
6
6
  import { simpleGit } from 'simple-git';
7
7
  import { homedir } from 'os'
8
- import { runPipeline, checkYunxiaoToken } from './lib/pipelineApi.mjs';
8
+ import { runPipeline, checkYunxiaoToken, triggerPipeline } from './lib/pipelineApi.mjs';
9
9
 
10
10
  const TEST_SERVER_HOST = "192.168.0.35";
11
11
  /**
@@ -89,7 +89,7 @@ async function main() {
89
89
  // return;
90
90
  // other commands
91
91
  let command = process.argv[2];
92
- if (!["init", "prod", "test", "scp", "scpevt"].includes(command)) {
92
+ if (!["init", "prod", "test", "scp", "scpevt", "pipeline"].includes(command)) {
93
93
  command = "help";
94
94
  }
95
95
 
@@ -103,6 +103,7 @@ async function main() {
103
103
  console.log(`command: scp {file} {dest} 复制文件{file}到OfficialSite测试服务器{dest}`);
104
104
  console.log(`command: scpevt {file} 复制文件{file}到events测试服务器{file}`);
105
105
  console.log(`command: scpevt {file} {dest} 复制文件{file}到events测试服务器{dest}`);
106
+ console.log(`command: pipeline {pipelineName|pipelineId} 触发流水线{pipelineName|pipelineId}`);
106
107
  process.exit(0);
107
108
  } else if (command === "init") {
108
109
  await initConfigJson();
@@ -145,6 +146,20 @@ async function main() {
145
146
  await scpClient.uploadFile(srcFilePath, destPath);
146
147
  console.log(`scp done.`);
147
148
  process.exit(0);
149
+ } else if (command === "pipeline") {
150
+ const pipelineName = process.argv[3];
151
+ if (!pipelineName) {
152
+ console.log(`pipeline参数不能为空`);
153
+ process.exit(1);
154
+ }
155
+ try {
156
+ await triggerPipeline(pipelineName);
157
+ process.exit(0);
158
+ } catch (error) {
159
+ console.log(`触发流水线失败: ${error}`);
160
+ process.exit(1);
161
+ }
162
+
148
163
  }
149
164
  try {
150
165
  const workDir = process.cwd(); // 当前项目根目录
@@ -3,7 +3,7 @@ import { join } from 'node:path';
3
3
  import fs from 'node:fs';
4
4
  import simpleGit from 'simple-git';
5
5
 
6
- import { createPipelineRunFunc, getLatestPipelineRunFunc, listPipelinesFunc } from '../modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipeline.js'
6
+ import { createPipelineRunFunc, listPipelinesFunc, getPipelineFunc } from '../modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipeline.js'
7
7
 
8
8
  export const organizationId = "5ec8bb7bd1d1abe63b55cd33";
9
9
 
@@ -83,14 +83,34 @@ async function getPipelineInfoByName(name) {
83
83
  pipeline = pipelines.items.find(item => item.name === name);
84
84
  }
85
85
  } catch (error) {
86
- throw new Error(`获取流水线信息失败, 请确认流水线名称: ${name} 是否正确或检查云效token的权限是否足够: ${error}`);
86
+ throw new Error(`获取流水线信息失败, 请确认流水线名称:【${name}】是否正确或检查云效token的权限是否足够: ${error}`);
87
87
  }
88
88
  if (!pipeline) {
89
- throw new Error(`未找到对应的流水线, 请确认流水线名称: ${name} 是否正确或检查云效token的权限是否足够`);
89
+ throw new Error(`未找到对应的流水线, 请确认流水线名称:【${name}】是否正确或检查云效token的权限是否足够`);
90
90
  }
91
91
  return pipeline;
92
92
  }
93
93
 
94
+ export async function triggerPipeline(pipelineName) {
95
+ const yunxiaoToken = getYunxiaoToken({});
96
+ if(!yunxiaoToken) {
97
+ throw new Error(`未设置云效token, 请检查云效token是否正确`);
98
+ }
99
+ let pipelineID = "";
100
+ let name = pipelineName;
101
+ if(/^\d+$/.test(pipelineName)) {
102
+ pipelineID = pipelineName;
103
+ const pipelineInfo = await getPipelineFunc(organizationId, pipelineID);
104
+ name = pipelineInfo.name;
105
+ } else {
106
+ const pipelineInfo = await getPipelineInfoByName(pipelineName);
107
+ pipelineID = pipelineInfo.id;
108
+ name = pipelineInfo.name;
109
+ }
110
+ const runId = await createPipelineRunFunc(organizationId, pipelineID, {});
111
+ const pipelineRunDetailUrl = `https://flow.aliyun.com/pipelines/${pipelineID}/builds/${runId}`;
112
+ console.log(`流水线${name}[${pipelineID}]触发成功,流水线执行id: ${runId}, 流水线执行详情: ${pipelineRunDetailUrl}`);
113
+ }
94
114
 
95
115
 
96
116
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",