本文整理匯總了TypeScript中vsts-task-lib.error函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript error函數的具體用法?TypeScript error怎麽用?TypeScript error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了error函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: main
async function main(): Promise<void> {
tl.setResourcePath(path.join(__dirname, "task.json"));
try {
// Local feeds
const internalFeeds = await auth.getInternalAuthInfoArray("feedList");
// external service endpoints
const externalEndpoints = await auth.getExternalAuthInfoArray("externalSources");
// combination of both internal and external
const newEndpointsToAdd = internalFeeds.concat(externalEndpoints);
let pypircPath = utils.getPypircPath();
// Case when there are multiple twine auth tasks in a build
if (tl.exist(pypircPath)) {
// merge two tasks
tl.debug(tl.loc("Info_StartParsingExistingPypircFile", pypircPath));
let fileContent = ini.parse(fs.readFileSync(pypircPath, "utf-8"));
// Adding new endpoints to already existing .pypirc file.
for (const entry of newEndpointsToAdd){
if (entry.packageSource.feedName in fileContent){
// Hard fail if there is a name collision from service endpoint
throw new Error(tl.loc("Error_DuplicateEntryForExternalFeed",
entry.packageSource.feedName));
}
fileContent[entry.packageSource.feedName] = new Repository(
entry.packageSource.feedUri,
entry.username,
entry.password);
fileContent["distutils"]["index-servers"] += " " + entry.packageSource.feedName;
}
let encodedStr = ini.encode(fileContent);
fs.writeFileSync(pypircPath, encodedStr);
}
else {
// create new
fs.writeFileSync(pypircPath, formPypircFormatFromData(newEndpointsToAdd));
tl.setVariable("PYPIRC_PATH", pypircPath, false);
tl.debug(tl.loc("VariableSetForPypirc", pypircPath));
}
// Configuring the pypirc file
console.log(tl.loc("Info_SuccessAddingAuth", internalFeeds.length, externalEndpoints.length));
}
catch (error) {
tl.error(error);
tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToAddAuthentication"));
return;
} finally{
_logTwineAuthStartupVariables();
}
}
示例2: getArtifactToolFromService
export async function getArtifactToolFromService(serviceUri: string, accessToken: string, toolName: string){
let osName = tl.osType();
let arch = os.arch();
if(osName === "Windows_NT"){
osName = "windows";
}
if (arch === "x64"){
arch = "amd64";
}
const blobstoreAreaName = "clienttools";
const blobstoreAreaId = "187ec90d-dd1e-4ec6-8c57-937d979261e5";
const ApiVersion = "5.0-preview";
const blobstoreConnection = getWebApiWithProxy(serviceUri, accessToken);
try{
const artifactToolGetUrl = await blobstoreConnection.vsoClient.getVersioningData(ApiVersion,
blobstoreAreaName, blobstoreAreaId, { toolName }, {osName, arch});
const artifactToolUri = await blobstoreConnection.rest.get(artifactToolGetUrl.requestUrl);
if (artifactToolUri.statusCode !== 200){
tl.debug(tl.loc("Error_UnexpectedErrorFailedToGetToolMetadata", artifactToolUri.toString()));
throw new Error(tl.loc("Error_UnexpectedErrorFailedToGetToolMetadata", artifactToolGetUrl.requestUrl));
}
let artifactToolPath = toollib.findLocalTool(toolName, artifactToolUri.result.version);
if (!artifactToolPath) {
tl.debug(tl.loc("Info_DownloadingArtifactTool", artifactToolUri.result.uri));
const zippedToolsDir: string = await toollib.downloadTool(artifactToolUri.result.uri);
tl.debug("Downloaded zipped artifact tool to " + zippedToolsDir);
const unzippedToolsDir = await extractZip(zippedToolsDir);
artifactToolPath = await toollib.cacheDir(unzippedToolsDir, "ArtifactTool", artifactToolUri.result.version);
}
else{
tl.debug(tl.loc("Info_ResolvedToolFromCache", artifactToolPath));
}
return getArtifactToolLocation(artifactToolPath);
}
catch(err){
tl.error(err);
tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToGetArtifactTool", err));
}
}
示例3: run
export async function run(artifactToolPath: string): Promise<void> {
let buildIdentityDisplayName: string = null;
let buildIdentityAccount: string = null;
try {
// Get directory to publish
let downloadDir: string = tl.getInput("downloadDirectory");
if (downloadDir.length < 1)
{
tl.warning(tl.loc("Info_DownloadDirectoryNotFound"));
return;
}
let serviceUri: string;
let feedId: string;
let packageName: string;
let version: string;
// Feed Auth
let feedType = tl.getInput("internalOrExternalDownload") || "internal";
const normalizedFeedType = ["internal", "external"].find((x) =>
feedType.toUpperCase() === x.toUpperCase());
if (!normalizedFeedType) {
throw new Error(tl.loc("UnknownFeedType", feedType));
}
feedType = normalizedFeedType;
let internalAuthInfo: auth.InternalAuthInfo;
let toolRunnerOptions = artifactToolRunner.getOptions();
if (feedType === "internal")
{
// getting inputs
serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
feedId = tl.getInput("feedListDownload");
// Getting package name from package Id
const packageId = tl.getInput("packageListDownload");
const accessToken = pkgLocationUtils.getSystemAccessToken();
internalAuthInfo = new auth.InternalAuthInfo([], accessToken);
const feedUri = await pkgLocationUtils.getFeedUriFromBaseServiceUri(serviceUri, accessToken);
packageName = await artifactToolUtilities.getPackageNameFromId(feedUri, accessToken, feedId, packageId);
version = tl.getInput("versionListDownload");
toolRunnerOptions.env.UNIVERSAL_DOWNLOAD_PAT = internalAuthInfo.accessToken;
}
else {
let externalAuthInfo = auth.GetExternalAuthInfo("externalEndpoint");
if (!externalAuthInfo)
{
tl.setResult(tl.TaskResult.Failed, tl.loc("Error_NoSourceSpecifiedForDownload"));
return;
}
serviceUri = externalAuthInfo.packageSource.accountUrl;
feedId = tl.getInput("feedDownloadExternal");
packageName = tl.getInput("packageDownloadExternal");
version = tl.getInput("versionDownloadExternal");
// Assuming only auth via PAT works for now
const tokenAuth = externalAuthInfo as auth.TokenExternalAuthInfo;
toolRunnerOptions.env.UNIVERSAL_DOWNLOAD_PAT = tokenAuth.token;
}
tl.debug(tl.loc("Info_UsingArtifactToolDownload"));
const downloadOptions = {
artifactToolPath,
feedId,
accountUrl: serviceUri,
packageName,
packageVersion: version,
} as artifactToolRunner.IArtifactToolOptions;
downloadPackageUsingArtifactTool(downloadDir, downloadOptions, toolRunnerOptions);
tl.setResult(tl.TaskResult.Succeeded, tl.loc("PackagesDownloadedSuccessfully"));
} catch (err) {
tl.error(err);
if (buildIdentityDisplayName || buildIdentityAccount) {
tl.warning(tl.loc("BuildIdentityPermissionsHint", buildIdentityDisplayName, buildIdentityAccount));
}
tl.setResult(tl.TaskResult.Failed, tl.loc("PackagesFailedToDownload"));
}
}
示例4: run
export async function run(artifactToolPath: string): Promise<void> {
let buildIdentityDisplayName: string = null;
let buildIdentityAccount: string = null;
try {
// Get directory to publish
let publishDir: string = tl.getInput("publishDirectory");
if (publishDir.length < 1)
{
tl.debug(tl.loc("Info_PublishDirectoryNotFound"));
return;
}
let serviceUri: string;
let feedId: string;
let packageName: string;
let version: string;
let accessToken: string;
let feedUri: string;
const versionRadio = tl.getInput("versionPublishSelector");
// Feed Auth
let feedType = tl.getInput("internalOrExternalPublish") || "internal";
const normalizedFeedType = ["internal", "external"].find((x) =>
feedType.toUpperCase() === x.toUpperCase());
if (!normalizedFeedType) {
throw new Error(tl.loc("UnknownFeedType", feedType));
}
feedType = normalizedFeedType;
let internalAuthInfo: auth.InternalAuthInfo;
let toolRunnerOptions = artifactToolRunner.getOptions();
if (feedType === "internal")
{
// getting inputs
serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
packageName = tl.getInput("packageListPublish");
feedId = tl.getInput("feedListPublish");
// Setting up auth info
accessToken = pkgLocationUtils.getSystemAccessToken();
internalAuthInfo = new auth.InternalAuthInfo([], accessToken);
toolRunnerOptions.env.UNIVERSAL_PUBLISH_PAT = internalAuthInfo.accessToken;
}
else {
const externalAuthInfo = auth.GetExternalAuthInfo("externalEndpoints");
if (!externalAuthInfo)
{
tl.setResult(tl.TaskResult.Failed, tl.loc("Error_NoSourceSpecifiedForPublish"));
return;
}
serviceUri = externalAuthInfo.packageSource.accountUrl;
feedId = tl.getInput("feedPublishExternal");
packageName = tl.getInput("packagePublishExternal");
// Assuming only auth via PAT works for now
accessToken = (externalAuthInfo as auth.TokenExternalAuthInfo).token;
toolRunnerOptions.env.UNIVERSAL_PUBLISH_PAT = accessToken;
}
if (versionRadio === "custom"){
version = tl.getInput("versionPublish");
}
else{
feedUri = await pkgLocationUtils.getFeedUriFromBaseServiceUri(serviceUri, accessToken);
let highestVersion = await artifactToolUtilities.getHighestPackageVersionFromFeed(feedUri, accessToken, feedId, packageName);
version = artifactToolUtilities.getVersionUtility(tl.getInput("versionPublishSelector"), highestVersion);
}
tl.debug(tl.loc("Info_UsingArtifactToolPublish"));
// tslint:disable-next-line:no-object-literal-type-assertion
const publishOptions = {
artifactToolPath,
feedId,
accountUrl: serviceUri,
packageName,
packageVersion: version,
} as artifactToolRunner.IArtifactToolOptions;
publishPackageUsingArtifactTool(publishDir, publishOptions, toolRunnerOptions);
tl.setResult(tl.TaskResult.Succeeded, tl.loc("PackagesPublishedSuccessfully"));
} catch (err) {
tl.error(err);
if (buildIdentityDisplayName || buildIdentityAccount) {
tl.warning(tl.loc("BuildIdentityPermissionsHint", buildIdentityDisplayName, buildIdentityAccount));
}
tl.setResult(tl.TaskResult.Failed, tl.loc("PackagesFailedToPublish"));
}
}
示例5: main
async function main(): Promise<void> {
tl.setResourcePath(path.join(__dirname, "task.json"));
try {
let packagingLocation: string;
let pipEnvVar: string = "";
if (tl.getVariable("PIP_EXTRA_INDEX_URL")) {
pipEnvVar = tl.getVariable("PIP_EXTRA_INDEX_URL");
}
const feedIds = tl.getDelimitedInput("feedList", ",");
// Local feeds
if (feedIds)
{
tl.debug(tl.loc("Info_AddingInternalFeeds", feedIds.length));
const serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
const localAccessToken = pkgLocationUtils.getSystemAccessToken();
try {
// This call is to get the packaging URI(abc.pkgs.vs.com) which is same for all protocols.
packagingLocation = await pkgLocationUtils.getNuGetUriFromBaseServiceUri(
serviceUri,
localAccessToken);
} catch (error) {
tl.debug(tl.loc("FailedToGetPackagingUri"));
tl.debug(JSON.stringify(error));
packagingLocation = serviceUri;
}
const globalWebApi = utils.getWebApi(packagingLocation, localAccessToken);
for (const feedId of feedIds) {
const feedUri = await utils.getPyPiSimpleApiFromFeedId(globalWebApi, feedId);
const pipUri = utils.formPipCompatibleUri("build", localAccessToken, feedUri);
pipEnvVar = pipEnvVar + " " + pipUri;
}
}
// external service endpoints
let endpointNames = tl.getDelimitedInput("externalSources", ',');
const externalEndpoints = auth.getExternalAuthInfoArray(endpointNames);
externalEndpoints.forEach((id) => {
const externalPipUri = utils.formPipCompatibleUri(id.username, id.password, id.packageSource.feedUri);
pipEnvVar = pipEnvVar + " " + externalPipUri;
});
// Setting variable
tl.setVariable("PIP_EXTRA_INDEX_URL", pipEnvVar, false);
console.log(tl.loc("Info_SuccessAddingAuth", feedIds.length, externalEndpoints.length));
const pipauthvar = tl.getVariable("PIP_EXTRA_INDEX_URL");
if (pipauthvar.length < pipEnvVar.length){
tl.warning(tl.loc("Warn_TooManyFeedEntries"));
}
tl.debug(pipEnvVar);
}
catch (error) {
tl.error(error);
tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToAddAuthentication"));
return;
} finally{
_logPipAuthStartupVariables();
}
}