forked from microsoft/azure-devops-node-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensionManagement.ts
41 lines (34 loc) · 1.99 KB
/
extensionManagement.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as common from './common';
import * as nodeApi from 'azure-devops-node-api';
import * as ExtensionManagementApi from 'azure-devops-node-api/ExtensionManagementApi';
import * as ExtensionManagementInterfaces from 'azure-devops-node-api/interfaces/ExtensionManagementInterfaces';
export async function run() {
const webApi: nodeApi.WebApi = await common.getWebApi();
const extensionManagementApiObject: ExtensionManagementApi.IExtensionManagementApi = await webApi.getExtensionManagementApi();
common.banner('Extension Management Samples');
common.heading('Get state information');
console.log('States:', await extensionManagementApiObject.getStates(true, true, true));
const publisherName = 'ms';
const extensionName = 'vss-releaseartifact';
const version = '0.1.35';
let alreadyInstalled = false;
if (await extensionManagementApiObject.getInstalledExtensionByName(publisherName, extensionName)) {
console.log('Extension has already been installed');
alreadyInstalled = true;
}
else {
common.heading('Install an extension');
await extensionManagementApiObject.installExtensionByName(publisherName, extensionName, version);
}
// Verify extension was actually created
let installedExtension: ExtensionManagementInterfaces.InstalledExtension = await extensionManagementApiObject.getInstalledExtensionByName(publisherName, extensionName);
console.log('The following extension was installed', installedExtension);
if(!alreadyInstalled){
common.heading('Uninstall the extension');
await extensionManagementApiObject.uninstallExtensionByName(publisherName, extensionName);
installedExtension = await extensionManagementApiObject.getInstalledExtensionByName(publisherName, extensionName);
console.log('Extension was uninstalled, looking for it returns', installedExtension);
}
common.heading('Get a token');
console.log('Token:' , await extensionManagementApiObject.getToken())
}