本文整理汇总了TypeScript中vso-node-api/WebApi.WebApi类的典型用法代码示例。如果您正苦于以下问题:TypeScript WebApi类的具体用法?TypeScript WebApi怎么用?TypeScript WebApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebApi类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
}
}
}
开发者ID:bleissem,项目名称:vsts-tasks,代码行数:27,代码来源:testagent.ts
示例2: main
async function main(): Promise<void> {
var feed = getProjectAndFeedIdFromInputParam("feed");
if(feed.projectId) {
throw new Error(tl.loc("UnsupportedProjectScopedFeeds"));
}
let feedId = feed.feedId;
let regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
let packageId = tl.getInput("definition");
if(!regexGuid.test(packageId)){
packageId = "Nuget_" + tl.getInput("definition");
}
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var accessToken = getAuthToken();
var credentialHandler = vsts.getBearerHandler(accessToken);
var vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
var coreApi = vssConnection.getCoreApi();
const retryLimitValue: string = tl.getVariable("VSTS_HTTP_RETRY");
const retryLimit: number = (!!retryLimitValue && !isNaN(parseInt(retryLimitValue))) ? parseInt(retryLimitValue) : 4;
tl.debug(`RetryLimit set to ${retryLimit}`);
await executeWithRetries("downloadPackage", () => downloadPackage(collectionUrl, accessToken, credentialHandler, feedId, packageId, version, downloadPath).catch((reason) => {
throw reason;
}), retryLimit);
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:29,代码来源:download.ts
示例3: getNuGetFeedRegistryUrl
export async function getNuGetFeedRegistryUrl(accessToken:string, feedId: string, nuGetVersion: VersionInfo): Promise<string>
{
const ApiVersion = "3.0-preview.1";
let PackagingAreaName: string = "nuget";
// If no version is received, V3 is assumed
let PackageAreaId: string = nuGetVersion && nuGetVersion.productVersion.a < 3 ? "5D6FC3B3-EF78-4342-9B6E-B3799C866CFA" : "9D3A4E8E-2F8F-4AE1-ABC2-B461A51CB3B3";
let credentialHandler = vsts.getBearerHandler(accessToken);
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
// The second element contains the transformed packaging URL
let packagingCollectionUrl = (await locationHelpers.assumeNuGetUriPrefixes(collectionUrl))[1];
if (!packagingCollectionUrl)
{
packagingCollectionUrl = collectionUrl;
}
const overwritePackagingCollectionUrl = tl.getVariable("NuGet.OverwritePackagingCollectionUrl");
if (overwritePackagingCollectionUrl) {
tl.debug("Overwriting packaging collection URL");
packagingCollectionUrl = overwritePackagingCollectionUrl;
}
let vssConnection = new vsts.WebApi(packagingCollectionUrl, credentialHandler);
let coreApi = vssConnection.getCoreApi();
let data = await Retry(async () => {
return await coreApi.vsoClient.getVersioningData(ApiVersion, PackagingAreaName, PackageAreaId, { feedId: feedId });
}, 4, 100);
return data.requestUrl;
}
开发者ID:bleissem,项目名称:vsts-tasks,代码行数:31,代码来源:Utility.ts
示例4: main
async function main(): Promise<void> {
let feedId = tl.getInput("feed");
let packageId = tl.getInput("definition");
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var accessToken = getAuthToken();
var credentialHandler = vsts.getBearerHandler(accessToken);
var vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
var coreApi = vssConnection.getCoreApi();
await downloadPackage(collectionUrl, credentialHandler, feedId, packageId, version, downloadPath);
}
开发者ID:colindembovsky,项目名称:vsts-tasks,代码行数:14,代码来源:download.ts
示例5: getFeedRegistryUrl
export async function getFeedRegistryUrl(feedId: string): Promise<string> {
const apiVersion = '3.0-preview.1';
const area = 'npm';
const locationId = 'D9B75B07-F1D9-4A67-AAA6-A4D9E66B3352';
let accessToken = getSystemAccessToken();
let credentialHandler = vsts.getBearerHandler(accessToken);
let collectionUrl = await getPackagingCollectionUrl();
let vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
let coreApi = vssConnection.getCoreApi();
let data = await coreApi.vsoClient.getVersioningData(apiVersion, area, locationId, { feedId: feedId });
return data.requestUrl;
}
开发者ID:colindembovsky,项目名称:vsts-tasks,代码行数:14,代码来源:util.ts
示例6: main
async function main(): Promise<void> {
let feedId = tl.getInput("feed");
let regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
let packageId = tl.getInput("definition");
if(!regexGuid.test(packageId)){
packageId = "Nuget_" + tl.getInput("definition");
}
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var accessToken = getAuthToken();
var credentialHandler = vsts.getBearerHandler(accessToken);
var vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
var coreApi = vssConnection.getCoreApi();
await downloadPackage(collectionUrl, accessToken, credentialHandler, feedId, packageId, version, downloadPath);
}
开发者ID:grawcho,项目名称:vso-agent-tasks,代码行数:20,代码来源:download.ts
示例7: getServiceEndPoint
export function getServiceEndPoint(feedId: string, accessToken: string, area: string, locationId: string ): Q.Promise<string>{
var collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var oauth = vstsWebApi.getBearerHandler(accessToken);
var connection = new vstsWebApi.WebApi(collectionUrl, oauth);
var coreApi = connection.getCoreApi();
var serviceURL = '';
return coreApi.vsoClient.getVersioningData("3.0-preview.1", area, locationId, { feedId: feedId })
.then((versioningData) => {
tl._writeLine("Found " + area + " endpoint: " + versioningData.requestUrl);
return versioningData.requestUrl;
})
.fail(err => {
tl.error(tl.loc("CouldNotFindServiceEndpoint", area));
tl.error(err);
tl.exit(1);
return '';
})
}
开发者ID:ivyzhu,项目名称:vsts-tasks,代码行数:22,代码来源:LocationHelpers.ts
示例8: downloadPackage
export async function downloadPackage(collectionUrl: string, credentialHandler: bearm.BearerCredentialHandler, feedId: string, packageId: string, version: string, downloadPath: string) {
var feedsUrl = collectionUrl.replace(".visualstudio.com",".feeds.visualstudio.com");
var feedConnection = new vsts.WebApi(feedsUrl, credentialHandler);
var packagesUrl = collectionUrl.replace(".visualstudio.com",".pkgs.visualstudio.com");
var packageConnection = new vsts.WebApi(packagesUrl, credentialHandler);
var packageUrl = await getNuGetPackageUrl(feedConnection.getCoreApi().vsoClient, feedId, packageId);
await new Promise((resolve, reject) => {
feedConnection.getCoreApi().restClient.get(packageUrl, ApiVersion, null, { responseIsCollection: false }, async function (error, status, result) {
if (!!error || status != 200) {
return reject(tl.loc("FailedToGetPackageMetadata", error));
}
var packageType = result.protocolType.toLowerCase();
var packageName = result.name;
if (packageType == "nuget") {
var getDownloadUrlPromise = getDownloadUrl(packageConnection.getCoreApi().vsoClient, feedId, packageName, version)
getDownloadUrlPromise.catch((error) => {
return reject(error)
});
var downloadUrl = await getDownloadUrlPromise;
if (!tl.exist(downloadPath)) {
tl.mkdirP(downloadPath);
}
var zipLocation = path.resolve(downloadPath, "../", packageName) + ".zip";
var unzipLocation = path.join(downloadPath, "");
console.log(tl.loc("StartingDownloadOfPackage", packageName, zipLocation));
var downloadNugetPackagePromise = downloadNugetPackage(packageConnection.getCoreApi(), downloadUrl, zipLocation);
downloadNugetPackagePromise.catch((error) => {
return reject(error)
});
await downloadNugetPackagePromise;
console.log(tl.loc("ExtractingNugetPackage", packageName, unzipLocation));
var unzipPromise = unzip(zipLocation, unzipLocation);
unzipPromise.catch((error) => {
return reject(error)
});
await unzipPromise;
if (tl.exist(zipLocation)) {
tl.rmRF(zipLocation, false);
}
return resolve();
}
else {
return reject(tl.loc("PackageTypeNotSupported"));
}
});
});
}
开发者ID:colindembovsky,项目名称:vsts-tasks,代码行数:62,代码来源:download.ts
示例9: parseInt
var promise = new Promise<void>(async (resolve, reject) => {
try {
agentApi.logDebug("Starting Tag XplatGenerateReleaseNotes task");
let tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
let teamProject = tl.getVariable("System.TeamProject");
let releaseId: number = parseInt(tl.getVariable("Release.ReleaseId"));
let releaseDefinitionId: number = parseInt(tl.getVariable("Release.DefinitionId"));
// Inputs
let environmentName: string = (tl.getInput("overrideStageName") || tl.getVariable("Release_EnvironmentName")).toLowerCase();
var templateLocation = tl.getInput("templateLocation", true);
var templateFile = tl.getInput("templatefile");
var inlineTemplate = tl.getInput("inlinetemplate");
var outputfile = tl.getInput("outputfile", true);
var outputVariableName = tl.getInput("outputVariableName");
var emptyDataset = tl.getInput("emptySetText");
let credentialHandler: vstsInterfaces.IRequestHandler = util.getCredentialHandler();
let vsts = new webApi.WebApi(tpcUri, credentialHandler);
var releaseApi: IReleaseApi = await vsts.getReleaseApi();
var buildApi: IBuildApi = await vsts.getBuildApi();
agentApi.logInfo("Getting the current release details");
var currentRelease = await releaseApi.getRelease(teamProject, releaseId);
if (!currentRelease) {
reject(`Unable to locate the current release with id ${releaseId}`);
return;
}
var environmentId = util.getReleaseDefinitionId(currentRelease.environments, environmentName);
let mostRecentSuccessfulDeployment = await util.getMostRecentSuccessfulDeployment(releaseApi, teamProject, releaseDefinitionId, environmentId);
let mostRecentSuccessfulDeploymentRelease: Release;
agentApi.logInfo(`Getting all artifacts in the current release...`);
var arifactsInThisRelease = util.getSimpleArtifactArray(currentRelease.artifacts);
agentApi.logInfo(`Found ${arifactsInThisRelease.length}`);
let arifactsInMostRecentRelease: util.SimpleArtifact[] = [];
var mostRecentSuccessfulDeploymentName: string = "";
if (mostRecentSuccessfulDeployment) {
// Get the release that the deployment was a part of - This is required for the templating.
mostRecentSuccessfulDeploymentRelease = await releaseApi.getRelease(teamProject, mostRecentSuccessfulDeployment.release.id);
agentApi.logInfo(`Getting all artifacts in the most recent successful release [${mostRecentSuccessfulDeployment.release.name}]...`);
arifactsInMostRecentRelease = util.getSimpleArtifactArray(mostRecentSuccessfulDeployment.release.artifacts);
mostRecentSuccessfulDeploymentName = mostRecentSuccessfulDeployment.release.name;
agentApi.logInfo(`Found ${arifactsInMostRecentRelease.length}`);
} else {
agentApi.logInfo(`Skipping fetching artifact in the most recent successful release as there isn't one.`);
// we need to set the last successful as the current release to templates can get some data
mostRecentSuccessfulDeploymentRelease = currentRelease;
}
var globalCommits: Change[] = [];
var globalWorkItems: ResourceRef[] = [];
for (var artifactInThisRelease of arifactsInThisRelease) {
agentApi.logInfo(`Looking at artifact [${artifactInThisRelease.artifactAlias}]`);
agentApi.logInfo(`Build Number: [${artifactInThisRelease.buildNumber}]`);
var buildNumberFromMostRecentBuild = null;
if (arifactsInMostRecentRelease.length > 0) {
agentApi.logInfo(`Looking for the [${artifactInThisRelease.artifactAlias}] in the most recent successful release [${mostRecentSuccessfulDeploymentName}]`);
for (var artifactInMostRecentRelease of arifactsInMostRecentRelease) {
if (artifactInThisRelease.artifactAlias.toLowerCase() === artifactInMostRecentRelease.artifactAlias.toLowerCase()) {
agentApi.logInfo(`Found artifact [${artifactInThisRelease.artifactAlias}] with build number [${artifactInThisRelease.buildNumber}] in release [${mostRecentSuccessfulDeploymentName}]`);
// Only get the commits and workitems if the builds are different
if (artifactInMostRecentRelease.buildNumber.toLowerCase() !== artifactInThisRelease.buildNumber.toLowerCase()) {
agentApi.logInfo(`Checking what commits and workitems have changed from [${artifactInMostRecentRelease.buildNumber}] => [${artifactInThisRelease.buildNumber}]`);
var commits = await buildApi.getChangesBetweenBuilds(teamProject, parseInt(artifactInMostRecentRelease.buildId), parseInt(artifactInThisRelease.buildId), 5000);
var workitems = await buildApi.getWorkItemsBetweenBuilds(teamProject, parseInt(artifactInMostRecentRelease.buildId), parseInt(artifactInThisRelease.buildId), 5000);
var commitCount: number = 0;
var workItemCount: number = 0;
if (commits) {
commitCount = commits.length;
globalCommits = globalCommits.concat(commits);
}
if (workitems) {
workItemCount = workitems.length;
globalWorkItems = globalWorkItems.concat(workitems);
}
agentApi.logInfo(`Detected ${commitCount} commits/changesets and ${workItemCount} workitems between the builds.`);
} else {
agentApi.logInfo(`Build for artifact [${artifactInThisRelease.artifactAlias}] has not changed. Nothing to do`);
}
}
}
}
agentApi.logInfo(``);
//.........这里部分代码省略.........
开发者ID:Edgixshua,项目名称:vNextBuild,代码行数:101,代码来源:GenerateReleaseNotes.ts
示例10: getBasicHandler
var promise = new Promise<void>(async (resolve, reject) => {
var connection = tl.getInput("connection", true);
var projectId = tl.getInput("project", true);
var definitionId = tl.getInput("definition", true);
var buildId = tl.getInput("version", true);
var itemPattern = tl.getInput("itemPattern", true);
var downloadPath = tl.getInput("downloadPath", true);
var endpointUrl = tl.getEndpointUrl(connection, false);
var username = tl.getEndpointAuthorizationParameter(connection, 'username', true);
var accessToken = tl.getEndpointAuthorizationParameter(connection, 'apitoken', true)
|| tl.getEndpointAuthorizationParameter(connection, 'password', true);
var credentialHandler = getBasicHandler(username, accessToken);
var vssConnection = new WebApi(endpointUrl, credentialHandler);
var debugMode = tl.getVariable('System.Debug');
var verbose = debugMode ? debugMode.toLowerCase() != 'false' : false;
var parallelLimit: number = +tl.getVariable("release.artifact.download.parallellimit");
var templatePath = path.join(__dirname, 'vsts.handlebars');
var buildApi = vssConnection.getBuildApi();
var artifacts = await executeWithRetries("getArtifacts", () => buildApi.getArtifacts(parseInt(buildId), projectId), 3).catch((reason) => {
reject(reason);
});
if (artifacts) {
var downloadPromises: Array<Promise<any>> = [];
console.log("Linked artifacts count: " + artifacts.length);
artifacts.forEach(async function (artifact, index, artifacts) {
let downloaderOptions = new engine.ArtifactEngineOptions();
downloaderOptions.itemPattern = itemPattern;
downloaderOptions.verbose = verbose;
if (parallelLimit) {
downloaderOptions.parallelProcessingLimit = parallelLimit;
}
if (artifact.resource.type.toLowerCase() === "container") {
let downloader = new engine.ArtifactEngine();
var containerParts: string[] = artifact.resource.data.split('/', 3);
if (containerParts.length !== 3) {
throw new Error(tl.loc("FileContainerInvalidArtifactData"));
}
var containerId: number = parseInt(containerParts[1]);
var containerPath: string = containerParts[2];
var itemsUrl = endpointUrl + "/_apis/resources/Containers/" + containerId + "?itemPath=" + encodeURIComponent(containerPath) + "&isShallow=true";
itemsUrl = itemsUrl.replace(/([^:]\/)\/+/g, "$1");
console.log(tl.loc("DownloadArtifacts", itemsUrl));
var variables = {};
var handler = username ? new webHandlers.BasicCredentialHandler(username, accessToken) : new webHandlers.PersonalAccessTokenCredentialHandler(accessToken);
var webProvider = new providers.WebProvider(itemsUrl, templatePath, variables, handler);
var fileSystemProvider = new providers.FilesystemProvider(downloadPath);
downloadPromises.push(downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).catch((reason) => {
reject(reason);
}));
}
else if (artifact.resource.type.toLowerCase() === "filepath") {
let downloader = new engine.ArtifactEngine();
let downloadUrl = artifact.resource.data;
let artifactLocation = downloadUrl + '/' + artifact.name;
if (!fs.existsSync(artifactLocation)) {
console.log(tl.loc("ArtifactNameDirectoryNotFound", artifactLocation, downloadUrl));
artifactLocation = downloadUrl;
}
console.log(tl.loc("DownloadArtifacts", artifactLocation));
var fileShareProvider = new providers.FilesystemProvider(artifactLocation);
var fileSystemProvider = new providers.FilesystemProvider(downloadPath + '\\' + artifact.name);
downloadPromises.push(downloader.processItems(fileShareProvider, fileSystemProvider, downloaderOptions).catch((reason) => {
reject(reason);
}));
}
else {
console.log(tl.loc('UnsupportedArtifactType', artifact.resource.type));
}
});
Promise.all(downloadPromises).then(() => {
console.log(tl.loc('ArtifactsSuccessfullyDownloaded', downloadPath));
resolve();
}).catch((error) => {
reject(error);
});
}
});
开发者ID:Microsoft,项目名称:vsts-rm-extensions,代码行数:91,代码来源:download.ts
注:本文中的vso-node-api/WebApi.WebApi类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论