本文整理汇总了TypeScript中vso-node-api/WebApi.WebApi.getBuildApi方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WebApi.getBuildApi方法的具体用法?TypeScript WebApi.getBuildApi怎么用?TypeScript WebApi.getBuildApi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vso-node-api/WebApi.WebApi
的用法示例。
在下文中一共展示了WebApi.getBuildApi方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
});
}
});
示例2: 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(``);
//.........这里部分代码省略.........
示例3: run
async function run() {
tl.debug("Starting Tag Build/Release task");
let tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
// try to get the build team project, in case it's different from the release team project
let teamProject = tl.getVariable("Build.ProjectName");
if (!teamProject || teamProject.length === 0) {
// fall back on the release team project
teamProject = tl.getVariable("System.TeamProject");
}
let type = tl.getInput("type", true);
let tags = tl.getDelimitedInput("tags", '\n', true);
let buildId = -1;
let bId = tl.getVariable("Build.BuildId");
// just for tests
if (bId === "-1") {
bId = null;
}
if (bId) {
buildId = parseInt(bId);
tl.debug(`Build ID = ${buildId}`);
} else {
if (type === "Build") {
return completeTask(false, "No build ID found - perhaps Type should be 'Release' not 'Build'?");
}
}
let releaseId = -1;
let rId = tl.getVariable("Release.ReleaseId");
if (rId) {
releaseId = parseInt(rId);
tl.debug(`Release ID = ${releaseId}`);
} else {
if (type === "Release") {
return completeTask(false, "No release ID found - perhaps Type should be 'Build' not 'Release'?");
}
}
// handle creds
let credHandler: vstsInterfaces.IRequestHandler;
let accessToken = tl.getVariable("System.AccessToken");
if (!accessToken || accessToken.length === 0) {
tl.setResult(tl.TaskResult.Failed, "Could not find token for autheniticating. Please enable OAuth token in Build/Release Options.");
tl.debug("Leaving Tag Build task");
return;
} else {
tl.debug("Detected token: creating bearer cred handler");
credHandler = webApi.getBearerHandler(accessToken);
}
let vsts = new webApi.WebApi(tpcUri, credHandler);
if (type === "Build") {
tl.debug("Getting build api client");
let buildApi = vsts.getBuildApi();
console.info(`Setting tags on build [${buildId}]`);
await buildApi.addBuildTags(tags, teamProject, buildId)
.then(tags => {
tl.debug(`New tags: ${tags.join(',')}`);
return completeTask(true, `Successfully added tags to the ${type}`);
})
.catch(e => tl.setResult(tl.TaskResult.Failed, e));
} else {
tl.debug("Getting release api client");
let releaseResourceArea;
try {
let locationClient = vsts.getLocationsApi();
releaseResourceArea = await locationClient.getResourceArea("efc2f575-36ef-48e9-b672-0c6fb4a48ac5");
} catch (e) {
console.warn("Could not get releaseResourceArea resource area: this may cause the task to fail.");
}
let releaseApi = vsts.getReleaseApi(releaseResourceArea ? releaseResourceArea.locationUrl : null);
console.info(`Setting tags on release [${releaseId}]`);
await releaseApi.addReleaseTags(tags, teamProject, releaseId)
.then(tags => {
tl.debug(`New tags: ${tags.join(',')}`);
return completeTask(true, `Successfully added tags to the ${type}`);
})
.catch(e => completeTask(false, e));
}
}