本文整理汇总了TypeScript中vso-node-api/WebApi.WebApi.getTestApi方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WebApi.getTestApi方法的具体用法?TypeScript WebApi.getTestApi怎么用?TypeScript WebApi.getTestApi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vso-node-api/WebApi.WebApi
的用法示例。
在下文中一共展示了WebApi.getTestApi方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createAgent
public static async createAgent(environment: models.DtaEnvironment, retries: number) {
var currentRetryCount = retries;
while(currentRetryCount > 0) {
currentRetryCount--;
try {
const envUrlRef: any = { Url: environment.environmentUri };
const machineNameRef: any = { Name: environment.agentName };
// TODO : Change any to appropriate types once promiseme package is avialable
const testAgent: any = {
Name: environment.agentName,
Capabilities: [],
DtlEnvironment: envUrlRef,
DtlMachine: machineNameRef };
const webapi: any = new webapim.WebApi(environment.tfsCollectionUrl, webapim.getBearerHandler(environment.patToken));
const testApi: any = webapi.getTestApi();
const registeredAgent = await testApi.createAgent(testAgent);
tl.debug('created the test agent entry in DTA service, id : ' + registeredAgent.id);
return registeredAgent.id;
} catch (error) {
tl.error('Error : created the test agent entry in DTA service, so retrying => retries pending : ' + currentRetryCount
+ 'error details :' + error);
if(currentRetryCount === 0) {
throw new Error(tl.loc("configureDtaAgentFailed", retries, error));
}
}
}
}
示例2: run
async function run() {
try {
tl.debug("Starting Coverage Gate task");
var tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
var teamProject = tl.getVariable("System.TeamProject");
var buildId = parseInt(tl.getVariable("Build.BuildId"));
var minDelta = parseInt(tl.getInput("minDelta", true));
var operator = tl.getInput("operator", true);
var username = tl.getInput("username", false);
var password = tl.getInput("password", false);
tl.debug(`minDelta: ${minDelta}`);
tl.debug(`operator: ${operator}`);
tl.debug(`username: ${username}`);
// handle creds
var credOk = true;
var credHandler: vstsInterfaces.IRequestHandler;
var accessToken = tl.getVariable("System.AccessToken");
if (!accessToken || accessToken.length === 0) {
if (username && username.length > 0) {
tl.debug("Detected username: creating basic cred handler");
credHandler = webApi.getBasicHandler(username, password);
} else {
tl.setResult(tl.TaskResult.Failed, "Could not find token for autheniticating. Please enable OAuth token in Build/Release Options or supply username/password.");
credOk = false;
}
} else {
tl.debug("Detected token: creating bearer cred handler");
credHandler = webApi.getBearerHandler(accessToken);
}
if (credOk) {
var vsts = new webApi.WebApi(tpcUri, credHandler);
// get previous successful builds
tl.debug("Connecting to test API");
var testApi = vsts.getTestApi();
tl.debug("Getting coverage data");
// 1 = modules, 2 = function, 4 = block
var covData = await testApi.getCodeCoverageSummary(teamProject, buildId);
tl.debug("Analyzing coverage data");
if (covData) {
var data = covData.coverageData[0];
var trends = data.coverageStats.filter(c => c.isDeltaAvailable)
.map(u => {
return {
Label: u.label,
Delta: u.delta
};
});
if (trends.length === 0){
tl.setResult(tl.TaskResult.Failed, `There are no coverage deltas. Make sure you have at least 2 builds.`);
}
var fail = trends.some(t => operator === 'lt' ? t.Delta < minDelta : t.Delta <= minDelta);
if (fail) {
tl.setResult(tl.TaskResult.Failed, `Coverage delta is below the threshold of ${minDelta}`);
}
} else {
tl.setResult(tl.TaskResult.Failed, "No coverage data for build. Cannot determine trend.");
}
tl.setResult(tl.TaskResult.Succeeded, `Code coverage delta is above the threshold of ${minDelta}`);
}
} catch (err) {
tl.debug("Caught an error - logging");
let msg = err;
if (err.message) {
msg = err.message;
}
tl.setResult(tl.TaskResult.Failed, msg);
}
tl.debug("Leaving Coverage Gate task");
}