Skip to content

Commit d93a4e1

Browse files
authored
use ado-node-api (#19389)
1 parent 058392a commit d93a4e1

File tree

10 files changed

+281
-240
lines changed

10 files changed

+281
-240
lines changed

ci/ci-test-tasks/test-and-verify-v2/package-lock.json

Lines changed: 131 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci/ci-test-tasks/test-and-verify-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"build": "tsc"
55
},
66
"dependencies": {
7-
"axios": "^1.6.2"
7+
"azure-devops-node-api": "^12.1.0"
88
},
99
"devDependencies": {
1010
"@tsconfig/node20": "^20.1.2",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { WebApi, getPersonalAccessTokenHandler } from 'azure-devops-node-api';
2+
import { IBuildApi } from 'azure-devops-node-api/BuildApi';
3+
4+
class API {
5+
public readonly tasks: string[];
6+
7+
private readonly projectName: string;
8+
private readonly webApi: WebApi;
9+
private buildApi: IBuildApi | null = null;
10+
11+
constructor(argv: string[]) {
12+
const authToken = argv[2];
13+
if (!authToken) {
14+
throw new Error('Auth token is not provided');
15+
}
16+
const adoUrl = argv[3];
17+
if (!adoUrl) {
18+
throw new Error('ADO url is not provided');
19+
}
20+
this.projectName = argv[4];
21+
if (!this.projectName) {
22+
throw new Error('Project name is not provided');
23+
}
24+
const TaskArg = argv[5];
25+
if (!TaskArg) {
26+
throw new Error('Task list is not provided');
27+
}
28+
29+
this.tasks = TaskArg.split(',');
30+
const authHandler = getPersonalAccessTokenHandler(authToken);
31+
this.webApi = new WebApi(adoUrl, authHandler);
32+
}
33+
34+
public async getDefinitions () {
35+
const api = await this.getBuildApi();
36+
37+
return await api.getDefinitions(this.projectName);
38+
}
39+
40+
public async getBuild (buildId: number) {
41+
const api = await this.getBuildApi();
42+
43+
return await api.getBuild(this.projectName, buildId);
44+
}
45+
46+
public async queueBuild (definitionId: number, parameters = {}) {
47+
const api = await this.getBuildApi();
48+
49+
return await api.queueBuild({
50+
definition: { id: definitionId },
51+
parameters: JSON.stringify(parameters)
52+
}, this.projectName);
53+
}
54+
55+
public async updateBuild (buildId: number) {
56+
const api = await this.getBuildApi();
57+
58+
return await api.updateBuild({}, this.projectName, buildId, true);
59+
}
60+
61+
private async getBuildApi () {
62+
if (!this.buildApi) this.buildApi = await this.webApi.getBuildApi();
63+
64+
return this.buildApi;
65+
}
66+
}
67+
68+
export const api = new API(process.argv);

ci/ci-test-tasks/test-and-verify-v2/src/config.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

ci/ci-test-tasks/test-and-verify-v2/src/constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)