azure-devops-task-utils 3.0.0 → 4.0.0
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/LICENSE +21 -0
- package/README.md +51 -2
- package/lib/api.d.ts +7 -0
- package/lib/api.js +52 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +18 -0
- package/lib/task.d.ts +8 -0
- package/lib/task.js +58 -0
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +19 -0
- package/package.json +23 -26
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -103
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 David Polania
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,2 +1,51 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Azure DevOps task utils
|
|
2
|
+
Library with useful functionalities for azure devops tasks
|
|
3
|
+
|
|
4
|
+
- Create client
|
|
5
|
+
- Update variable
|
|
6
|
+
- retries
|
|
7
|
+
- etc
|
|
8
|
+
|
|
9
|
+
# Usage
|
|
10
|
+
|
|
11
|
+
```sh-session
|
|
12
|
+
$ npm install --save azure-devops-task-utils
|
|
13
|
+
...
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
````
|
|
18
|
+
import * as common from 'azure-devops-task-utils';
|
|
19
|
+
import * as nodeApi from 'azure-devops-node-api';
|
|
20
|
+
|
|
21
|
+
async function sample() {
|
|
22
|
+
|
|
23
|
+
common.banner('Init Configuration');
|
|
24
|
+
common.heading('Title');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const webApi: nodeApi.WebApi = await common.getWebApi();
|
|
28
|
+
const gitApi: GitApi.IGitApi = await webApi.getGitApi();
|
|
29
|
+
const project: string = common.getProject();
|
|
30
|
+
|
|
31
|
+
///
|
|
32
|
+
gitApi.
|
|
33
|
+
.
|
|
34
|
+
.
|
|
35
|
+
.
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
````
|
|
40
|
+
|
|
41
|
+
To do local tests export the variables y en la variable 'SYSTEM_ACCESSTOKEN' a personal access token
|
|
42
|
+
|
|
43
|
+
export SYSTEM_ACCESSTOKEN=xxxxx
|
|
44
|
+
|
|
45
|
+
export SYSTEM_TEAMPROJECTID=xxxxx-xxx-xx
|
|
46
|
+
|
|
47
|
+
export SYSTEM_TEAMFOUNDATIONCOLLECTIONURI=https://dev.azure.com/xxxxxxxx/
|
|
48
|
+
|
|
49
|
+
Nota: In Azure DevOps you must activate the option to use auth script in the agents
|
|
50
|
+
|
|
51
|
+
"Allow scripts to access the OAuth token"
|
package/lib/api.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigurationVariableValue, Release } from 'azure-devops-node-api/interfaces/ReleaseInterfaces';
|
|
2
|
+
import { WebApi } from 'azure-devops-node-api';
|
|
3
|
+
import { ConnectionData } from 'azure-devops-node-api/interfaces/LocationsInterfaces';
|
|
4
|
+
import { IRequestOptions } from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces';
|
|
5
|
+
export declare function testConnection(webApi: WebApi): Promise<ConnectionData>;
|
|
6
|
+
export declare function createWebApi(serverUrl: string, token: string, apiOptions?: IRequestOptions): WebApi;
|
|
7
|
+
export declare function setReleaseVariableFromApi(webApi: WebApi, project: string, releaseId: number, variableName: string, configurationVariable: ConfigurationVariableValue): Promise<Release>;
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setReleaseVariableFromApi = exports.createWebApi = exports.testConnection = void 0;
|
|
13
|
+
const azure_devops_node_api_1 = require("azure-devops-node-api");
|
|
14
|
+
function testConnection(webApi) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const connData = yield webApi.connect();
|
|
17
|
+
const name = connData && connData.authenticatedUser && connData.authenticatedUser.providerDisplayName;
|
|
18
|
+
console.log(`Hello ${name}`);
|
|
19
|
+
return connData;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.testConnection = testConnection;
|
|
23
|
+
function createWebApi(serverUrl, token, apiOptions) {
|
|
24
|
+
try {
|
|
25
|
+
const authHandler = (0, azure_devops_node_api_1.getHandlerFromToken)(token);
|
|
26
|
+
const webApi = new azure_devops_node_api_1.WebApi(serverUrl, authHandler, apiOptions);
|
|
27
|
+
return webApi;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw new Error(err.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.createWebApi = createWebApi;
|
|
34
|
+
function setReleaseVariableFromApi(webApi, project, releaseId, variableName, configurationVariable) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
try {
|
|
37
|
+
const releaseApi = yield webApi.getReleaseApi();
|
|
38
|
+
const release = yield releaseApi.getRelease(project, releaseId);
|
|
39
|
+
if (release.variables) {
|
|
40
|
+
release.variables[variableName] = configurationVariable;
|
|
41
|
+
return yield releaseApi.updateRelease(release, project, Number(releaseId));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error('Variables is undefined');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error(error.message);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
exports.setReleaseVariableFromApi = setReleaseVariableFromApi;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryPromise = exports.retryFunction = exports.heading = exports.banner = exports.setReleaseVariable = exports.getWebApi = exports.getProject = exports.getVariableRequired = exports.isVariable = exports.testConnection = exports.createWebApi = exports.setReleaseVariableFromApi = void 0;
|
|
4
|
+
var api_1 = require("./api");
|
|
5
|
+
Object.defineProperty(exports, "setReleaseVariableFromApi", { enumerable: true, get: function () { return api_1.setReleaseVariableFromApi; } });
|
|
6
|
+
Object.defineProperty(exports, "createWebApi", { enumerable: true, get: function () { return api_1.createWebApi; } });
|
|
7
|
+
Object.defineProperty(exports, "testConnection", { enumerable: true, get: function () { return api_1.testConnection; } });
|
|
8
|
+
var task_1 = require("./task");
|
|
9
|
+
Object.defineProperty(exports, "isVariable", { enumerable: true, get: function () { return task_1.isVariable; } });
|
|
10
|
+
Object.defineProperty(exports, "getVariableRequired", { enumerable: true, get: function () { return task_1.getVariableRequired; } });
|
|
11
|
+
Object.defineProperty(exports, "getProject", { enumerable: true, get: function () { return task_1.getProject; } });
|
|
12
|
+
Object.defineProperty(exports, "getWebApi", { enumerable: true, get: function () { return task_1.getWebApi; } });
|
|
13
|
+
Object.defineProperty(exports, "setReleaseVariable", { enumerable: true, get: function () { return task_1.setReleaseVariable; } });
|
|
14
|
+
var utils_1 = require("./utils");
|
|
15
|
+
Object.defineProperty(exports, "banner", { enumerable: true, get: function () { return utils_1.banner; } });
|
|
16
|
+
Object.defineProperty(exports, "heading", { enumerable: true, get: function () { return utils_1.heading; } });
|
|
17
|
+
Object.defineProperty(exports, "retryFunction", { enumerable: true, get: function () { return utils_1.retryFunction; } });
|
|
18
|
+
Object.defineProperty(exports, "retryPromise", { enumerable: true, get: function () { return utils_1.retryPromise; } });
|
package/lib/task.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Release } from 'azure-devops-node-api/interfaces/ReleaseInterfaces';
|
|
2
|
+
import { IRequestOptions } from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces';
|
|
3
|
+
import { WebApi } from 'azure-devops-node-api';
|
|
4
|
+
export declare function isVariable(name: string): boolean;
|
|
5
|
+
export declare function getVariableRequired(name: string, customMessage?: string): string;
|
|
6
|
+
export declare function getProject(): string;
|
|
7
|
+
export declare function getWebApi(apiOptions?: IRequestOptions): WebApi;
|
|
8
|
+
export declare function setReleaseVariable(releaseId: number, variableName: string, variableValue: string, allowOverride?: boolean, isSecret?: boolean): Promise<Release>;
|
package/lib/task.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setReleaseVariable = exports.getWebApi = exports.getProject = exports.getVariableRequired = exports.isVariable = void 0;
|
|
13
|
+
const api_1 = require("./api");
|
|
14
|
+
const azure_pipelines_task_lib_1 = require("azure-pipelines-task-lib");
|
|
15
|
+
function isVariable(name) {
|
|
16
|
+
return !!(0, azure_pipelines_task_lib_1.getVariable)(name);
|
|
17
|
+
}
|
|
18
|
+
exports.isVariable = isVariable;
|
|
19
|
+
function getVariableRequired(name, customMessage) {
|
|
20
|
+
const value = (0, azure_pipelines_task_lib_1.getVariable)(name);
|
|
21
|
+
if (!value) {
|
|
22
|
+
console.log(customMessage);
|
|
23
|
+
console.error(name + ' env var not set. It is not found in the agent variables');
|
|
24
|
+
throw new Error(`Variable required: ${name}`);
|
|
25
|
+
}
|
|
26
|
+
(0, azure_pipelines_task_lib_1.debug)(`${name} = ${value}`);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
exports.getVariableRequired = getVariableRequired;
|
|
30
|
+
function getProject() {
|
|
31
|
+
return getVariableRequired('SYSTEM_TEAMPROJECTID');
|
|
32
|
+
}
|
|
33
|
+
exports.getProject = getProject;
|
|
34
|
+
function getWebApi(apiOptions) {
|
|
35
|
+
const serverUrl = getVariableRequired('SYSTEM_TEAMFOUNDATIONCOLLECTIONURI');
|
|
36
|
+
const token = getVariableRequired('SYSTEM_ACCESSTOKEN', 'Remember to enable in the agent "Allow scripts to access the OAuth token"');
|
|
37
|
+
return (0, api_1.createWebApi)(serverUrl, token, apiOptions);
|
|
38
|
+
}
|
|
39
|
+
exports.getWebApi = getWebApi;
|
|
40
|
+
function setReleaseVariable(releaseId, variableName, variableValue, allowOverride = true, isSecret = false) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const webApi = getWebApi();
|
|
44
|
+
const project = getProject();
|
|
45
|
+
const variableConfiguration = {
|
|
46
|
+
allowOverride,
|
|
47
|
+
isSecret,
|
|
48
|
+
value: variableValue
|
|
49
|
+
};
|
|
50
|
+
(0, azure_pipelines_task_lib_1.setVariable)(variableName, variableValue, isSecret);
|
|
51
|
+
return yield (0, api_1.setReleaseVariableFromApi)(webApi, project, releaseId, variableName, variableConfiguration);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new Error(error.message);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.setReleaseVariable = setReleaseVariable;
|
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.heading = exports.banner = exports.retryPromise = exports.retryFunction = void 0;
|
|
4
|
+
var retry_1 = require("polallel/lib/retry");
|
|
5
|
+
Object.defineProperty(exports, "retryFunction", { enumerable: true, get: function () { return retry_1.retryFunction; } });
|
|
6
|
+
Object.defineProperty(exports, "retryPromise", { enumerable: true, get: function () { return retry_1.retryPromise; } });
|
|
7
|
+
function banner(title) {
|
|
8
|
+
console.log();
|
|
9
|
+
console.log('=======================================');
|
|
10
|
+
console.log('\t' + title);
|
|
11
|
+
console.log('=======================================');
|
|
12
|
+
console.log();
|
|
13
|
+
}
|
|
14
|
+
exports.banner = banner;
|
|
15
|
+
function heading(title) {
|
|
16
|
+
console.log();
|
|
17
|
+
console.log('> ' + title);
|
|
18
|
+
}
|
|
19
|
+
exports.heading = heading;
|
package/package.json
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azure-devops-task-utils",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Utility library for Azure DevOps tasks",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
8
|
+
"lib/**/*"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": " echo test run ",
|
|
12
11
|
"build": "tsc",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"prepublishOnly": "npm test && npm run lint",
|
|
17
|
-
"preversion": "npm run lint",
|
|
18
|
-
"version": "npm run format && git add -A src",
|
|
19
|
-
"postversion": "git push && git push --tags"
|
|
12
|
+
"prebuild": "rimraf ./lib",
|
|
13
|
+
"format": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
|
14
|
+
"lint": "eslint . --ext .ts"
|
|
20
15
|
},
|
|
21
16
|
"repository": {
|
|
22
17
|
"type": "git",
|
|
@@ -26,26 +21,28 @@
|
|
|
26
21
|
"azure",
|
|
27
22
|
"devops",
|
|
28
23
|
"tasks",
|
|
29
|
-
"
|
|
24
|
+
"utils"
|
|
30
25
|
],
|
|
31
|
-
"author": "
|
|
32
|
-
"license": "
|
|
26
|
+
"author": "davidpolaniaac",
|
|
27
|
+
"license": "MIT",
|
|
33
28
|
"bugs": {
|
|
34
29
|
"url": "https://github.com/davidpolaniaac/azure-devops-task-utils/issues"
|
|
35
30
|
},
|
|
36
31
|
"homepage": "https://github.com/davidpolaniaac/azure-devops-task-utils.git#readme",
|
|
37
32
|
"dependencies": {
|
|
38
|
-
"azure-devops-node-api": "^
|
|
39
|
-
"azure-pipelines-task-lib": "^
|
|
33
|
+
"azure-devops-node-api": "^11.2.0",
|
|
34
|
+
"azure-pipelines-task-lib": "^3.3.1",
|
|
35
|
+
"polallel": "^1.0.2"
|
|
40
36
|
},
|
|
41
37
|
"devDependencies": {
|
|
42
|
-
"@types/
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
38
|
+
"@types/node": "^14.14.31",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.38.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.38.0",
|
|
41
|
+
"eslint": "^8.24.0",
|
|
42
|
+
"eslint-config-prettier": "^8.5.0",
|
|
43
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
+
"prettier": "^2.7.1",
|
|
45
|
+
"rimraf": "^3.0.2",
|
|
46
|
+
"typescript": "^4.8.3"
|
|
50
47
|
}
|
|
51
48
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as vm from 'azure-devops-node-api';
|
|
2
|
-
import * as ReleaseInterfaces from 'azure-devops-node-api/interfaces/ReleaseInterfaces';
|
|
3
|
-
export declare function getWebApi(): Promise<vm.WebApi>;
|
|
4
|
-
export declare function getApi(serverUrl: string, optionApi?: any): Promise<vm.WebApi>;
|
|
5
|
-
export declare function getProject(): string;
|
|
6
|
-
export declare function banner(title: string): void;
|
|
7
|
-
export declare function heading(title: string): void;
|
|
8
|
-
export declare function setReleaseVariable(releaseId: number, variableName: string, variableValue: string, allowOverride?: boolean, isSecret?: boolean): Promise<ReleaseInterfaces.Release>;
|
package/dist/index.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
const vm = require("azure-devops-node-api");
|
|
12
|
-
const tl = require("azure-pipelines-task-lib/task");
|
|
13
|
-
function getEnv(name) {
|
|
14
|
-
const val = tl.getVariable(name);
|
|
15
|
-
if (!val) {
|
|
16
|
-
console.error(name + ' env var not set');
|
|
17
|
-
name.includes('SYSTEM_ACCESSTOKEN')
|
|
18
|
-
? console.log('Remember to enable in the agent "Allow scripts to access the OAuth token"')
|
|
19
|
-
: console.log('It is not found in the agent variables');
|
|
20
|
-
tl.setResult(tl.TaskResult.Failed, 'env var not set');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
return val;
|
|
24
|
-
}
|
|
25
|
-
function validateEnv(name) {
|
|
26
|
-
return !!tl.getVariable(name);
|
|
27
|
-
}
|
|
28
|
-
function getWebApi() {
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const serverUrl = getEnv('SYSTEM_TEAMFOUNDATIONCOLLECTIONURI');
|
|
31
|
-
return yield getApi(serverUrl);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.getWebApi = getWebApi;
|
|
35
|
-
function getApi(serverUrl, optionApi) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
try {
|
|
39
|
-
const token = validateEnv('SYSTEM_ACCESSTOKEN_LOCAL')
|
|
40
|
-
? getEnv('SYSTEM_ACCESSTOKEN_LOCAL')
|
|
41
|
-
: getEnv('SYSTEM_ACCESSTOKEN');
|
|
42
|
-
const authHandler = validateEnv('SYSTEM_ACCESSTOKEN_LOCAL')
|
|
43
|
-
? vm.getPersonalAccessTokenHandler(token)
|
|
44
|
-
: vm.getBearerHandler(token);
|
|
45
|
-
const option = optionApi;
|
|
46
|
-
const vsts = new vm.WebApi(serverUrl, authHandler, option);
|
|
47
|
-
const connData = yield vsts.connect();
|
|
48
|
-
resolve(vsts);
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
reject(err);
|
|
52
|
-
}
|
|
53
|
-
}));
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
exports.getApi = getApi;
|
|
57
|
-
function getProject() {
|
|
58
|
-
return getEnv('SYSTEM_TEAMPROJECTID');
|
|
59
|
-
}
|
|
60
|
-
exports.getProject = getProject;
|
|
61
|
-
function banner(title) {
|
|
62
|
-
console.log();
|
|
63
|
-
console.log('=======================================');
|
|
64
|
-
console.log('\t' + title);
|
|
65
|
-
console.log('=======================================');
|
|
66
|
-
console.log();
|
|
67
|
-
}
|
|
68
|
-
exports.banner = banner;
|
|
69
|
-
function heading(title) {
|
|
70
|
-
console.log();
|
|
71
|
-
console.log('> ' + title);
|
|
72
|
-
}
|
|
73
|
-
exports.heading = heading;
|
|
74
|
-
function setReleaseVariable(releaseId, variableName, variableValue, allowOverride = true, isSecret = false) {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
try {
|
|
78
|
-
const webApi = yield getWebApi();
|
|
79
|
-
const releaseApi = yield webApi.getReleaseApi();
|
|
80
|
-
const project = getProject();
|
|
81
|
-
tl.setVariable(variableName, variableValue);
|
|
82
|
-
const release = yield releaseApi.getRelease(project, releaseId);
|
|
83
|
-
const variableConfiguration = {
|
|
84
|
-
allowOverride,
|
|
85
|
-
isSecret,
|
|
86
|
-
value: variableValue
|
|
87
|
-
};
|
|
88
|
-
if (release.variables) {
|
|
89
|
-
release.variables[variableName] = variableConfiguration;
|
|
90
|
-
const newRelease = yield releaseApi.updateRelease(release, project, Number(releaseId));
|
|
91
|
-
resolve(newRelease);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
reject(new Error('Variables is undefined'));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
reject(error);
|
|
99
|
-
}
|
|
100
|
-
}));
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.setReleaseVariable = setReleaseVariable;
|