本文整理匯總了TypeScript中vsts-task-tool-lib/tool.cacheDir函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript cacheDir函數的具體用法?TypeScript cacheDir怎麽用?TypeScript cacheDir使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了cacheDir函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: downloadAndInstall
private async downloadAndInstall(downloadUrls: string[]) {
let downloaded = false;
let downloadPath = "";
for (const url of downloadUrls) {
try {
downloadPath = await toolLib.downloadTool(url);
downloaded = true;
break;
} catch (error) {
tl.warning(tl.loc("CouldNotDownload", url, JSON.stringify(error)));
}
}
if (!downloaded) {
throw tl.loc("FailedToDownloadPackage");
}
// extract
console.log(tl.loc("ExtractingPackage", downloadPath));
let extPath: string = tl.osType().match(/^Win/) ? await toolLib.extractZip(downloadPath) : await toolLib.extractTar(downloadPath);
// cache tool
console.log(tl.loc("CachingTool"));
let cachedDir = await toolLib.cacheDir(extPath, this.cachedToolName, this.version);
console.log(tl.loc("SuccessfullyInstalled", this.packageType, this.version));
return cachedDir;
}
示例2: acquireNodeFromFallbackLocation
// For non LTS versions of Node, the files we need (for Windows) are sometimes located
// in a different folder than they normally are for other versions.
// Normally the format is similar to: https://nodejs.org/dist/v5.10.1/node-v5.10.1-win-x64.7z
// In this case, there will be two files located at:
// /dist/v5.10.1/win-x64/node.exe
// /dist/v5.10.1/win-x64/node.lib
// If this is not the structure, there may also be two files located at:
// /dist/v0.12.18/node.exe
// /dist/v0.12.18/node.lib
// This method attempts to download and cache the resources from these alternative locations.
// Note also that the files are normally zipped but in this case they are just an exe
// and lib file in a folder, not zipped.
async function acquireNodeFromFallbackLocation(version: string): Promise<string> {
// Create temporary folder to download in to
let tempDownloadFolder: string = 'temp_' + Math.floor(Math.random() * 2000000000);
let tempDir: string = path.join(taskLib.getVariable('agent.tempDirectory'), tempDownloadFolder);
taskLib.mkdirP(tempDir);
let exeUrl: string;
let libUrl: string;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
await toolLib.downloadTool(exeUrl, path.join(tempDir, "node.exe"));
await toolLib.downloadTool(libUrl, path.join(tempDir, "node.lib"));
}
catch (err) {
if (err['httpStatusCode'] &&
err['httpStatusCode'] === '404')
{
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
await toolLib.downloadTool(exeUrl, path.join(tempDir, "node.exe"));
await toolLib.downloadTool(libUrl, path.join(tempDir, "node.lib"));
}
else {
throw err;
}
}
return await toolLib.cacheDir(tempDir, 'node', version);
}
示例3: acquireNode
async function acquireNode(version: string): Promise<string> {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
version = toolLib.cleanVersion(version);
let fileName: string = osPlat == 'win32'? 'node-v' + version + '-win-' + os.arch() :
'node-v' + version + '-' + osPlat + '-' + os.arch();
let urlFileName: string = osPlat == 'win32'? fileName + '.7z':
fileName + '.tar.gz';
let downloadUrl = 'https://nodejs.org/dist/v' + version + '/' + urlFileName;
let downloadPath: string;
try
{
downloadPath = await toolLib.downloadTool(downloadUrl);
}
catch (err)
{
if (err['httpStatusCode'] &&
err['httpStatusCode'] == '404')
{
return await acquireNodeFromFallbackLocation(version);
}
throw err;
}
//
// Extract
//
let extPath: string;
if (osPlat == 'win32') {
taskLib.assertAgent('2.115.0');
extPath = taskLib.getVariable('Agent.TempDirectory');
if (!extPath) {
throw new Error('Expected Agent.TempDirectory to be set');
}
extPath = path.join(extPath, 'n'); // use as short a path as possible due to nested node_modules folders
extPath = await toolLib.extract7z(downloadPath, extPath);
}
else {
extPath = await toolLib.extractTar(downloadPath);
}
//
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
//
let toolRoot = path.join(extPath, fileName);
return await toolLib.cacheDir(toolRoot, 'node', version);
}
示例4: acquireNodeFromFallbackLocation
// For non LTS versions of Node, the files we need (for Windows) are sometimes located
// in a different folder than they normally are for other versions.
// Normally the format is similar to: https://nodejs.org/dist/v5.10.1/node-v5.10.1-win-x64.7z
// In this case, there will be two files located at:
// /dist/v5.10.1/win-x64/node.exe
// /dist/v5.10.1/win-x64/node.lib
// This method attempts to download and cache the resources from this alternative location.
// Note also that the files are normally zipped but in this case they are just an exe
// and lib file in a folder, not zipped.
async function acquireNodeFromFallbackLocation(version: string): Promise<string> {
let exeUrl: string = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
let libUrl: string = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
// Create temporary folder to download in to
let tempDownloadFolder: string = 'temp_' + Math.floor(Math.random() * 2000000000);
let tempDir: string = path.join(taskLib.getVariable('agent.tempDirectory'), tempDownloadFolder);
taskLib.mkdirP(tempDir);
let exeDownloadPath: string = await toolLib.downloadTool(exeUrl, path.join(tempDir, "node.exe"));
let libDownloadPath: string = await toolLib.downloadTool(libUrl, path.join(tempDir, "node.lib"));
return await toolLib.cacheDir(tempDir, 'node', version);
}
示例5: 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));
}
}
示例6: acquireAndCacheVsTestPlatformNuget
// Downloads and caches the test platform package
private async acquireAndCacheVsTestPlatformNuget(packageSource: string, testPlatformVersion: string, nugetConfigFilePath: string): Promise<string> {
testPlatformVersion = toolLib.cleanVersion(testPlatformVersion);
const nugetTool = tl.tool(path.join(__dirname, 'nuget.exe'));
let downloadPath = helpers.getTempFolder();
// Ensure Agent.TempDirectory is set
if (!downloadPath) {
throw new Error(tl.loc('ExpectedTempToBeSet'));
}
// Call out a warning if the agent work folder path is longer than 50 characters as anything longer may cause the download to fail
// Note: This upper limit was calculated for a particular test platform package version and is subject to change
if (tl.getVariable(constants.agentWorkFolder) && tl.getVariable(constants.agentWorkFolder).length > 50) {
ci.addToConsolidatedCi('agentWorkDirectoryPathTooLong', 'true');
tl.warning(tl.loc('AgentWorkDirectoryPathTooLong'));
}
// Use as short a path as possible due to nested folders in the package that may potentially exceed the 255 char windows path limit
downloadPath = path.join(downloadPath, constants.toolFolderName);
nugetTool.arg(constants.install).arg(constants.packageId).arg(constants.version).arg(testPlatformVersion).arg(constants.source)
.arg(packageSource).arg(constants.outputDirectory).arg(downloadPath).arg(constants.noCache).arg(constants.directDownload)
.argIf(nugetConfigFilePath, constants.configFile).argIf(nugetConfigFilePath, nugetConfigFilePath).arg(constants.noninteractive);
tl.debug(`Downloading Test Platform version ${testPlatformVersion} from ${packageSource} to ${downloadPath}.`);
startTime = perf();
const resultCode = await nugetTool.exec();
ci.addToConsolidatedCi('downloadTime', perf() - startTime);
tl.debug(`Nuget.exe returned with result code ${resultCode}`);
if (resultCode !== 0) {
tl.error(tl.loc('NugetErrorCode', resultCode));
throw new Error(tl.loc('DownloadFailed', resultCode));
}
// Install into the local tool cache
const toolRoot = path.join(downloadPath, constants.packageId + '.' + testPlatformVersion);
tl.debug(`Caching the downloaded folder ${toolRoot}.`);
startTime = perf();
const vstestPlatformInstalledLocation = await toolLib.cacheDir(toolRoot, constants.toolFolderName, testPlatformVersion);
ci.addToConsolidatedCi('cacheTime', perf() - startTime);
return vstestPlatformInstalledLocation;
}
示例7: acquireGo
async function acquireGo(version: string): Promise<string> {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileName(version);
let downloadUrl: string = getDownloadUrl(fileName);
let downloadPath: string = null;
try {
downloadPath = await toolLib.downloadTool(downloadUrl);
} catch (error) {
tl.debug(error);
// cannot localized the string here because to localize we need to set the resource file.
// which can be set only once. vsts-task-tool-lib/tool, is already setting it to different file.
// So left with no option but to hardcode the string. Other tasks are doing the same.
throw (util.format("Failed to download version %s. Please verify that the version is valid and resolve any other issues. %s", version, error));
}
//make sure agent version is latest then 2.115.0
tl.assertAgent('2.115.0');
//
// Extract
//
let extPath: string;
extPath = tl.getVariable('Agent.TempDirectory');
if (!extPath) {
throw new Error("Expected Agent.TempDirectory to be set");
}
if (osPlat == 'win32') {
extPath = await toolLib.extractZip(downloadPath);
}
else {
extPath = await toolLib.extractTar(downloadPath);
}
//
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
//
let toolRoot = path.join(extPath, "go");
version = fixVersion(version);
return await toolLib.cacheDir(toolRoot, 'go', version);
}
示例8: acquireDotNetCore
async function acquireDotNetCore(packageType: string, version: string): Promise<string> {
let downloadUrls = getDownloadUrls(packageType, version);
let downloadPath: string;
try {
// try primary url
if (!!downloadUrls[0]) {
console.log(taskLib.loc("DownloadingPrimaryUrl", downloadUrls[0]));
downloadPath = await toolLib.downloadTool(downloadUrls[0]);
}
} catch (error1) {
console.log(taskLib.loc("PrimaryUrlDownloadFailed", error1));
try {
// try secondary url
if (!!downloadUrls[1]) {
console.log(taskLib.loc("DownloadingSecondaryUrl", downloadUrls[1]));
downloadPath = await toolLib.downloadTool(downloadUrls[1]);
}
} catch (error2) {
console.log(taskLib.loc("LegacyUrlDownloadFailed", error2));
throw taskLib.loc("DownloadFailed", packageType, version);
}
}
// extract
let extPath: string;
console.log(taskLib.loc("ExtractingPackage", downloadPath));
if (taskLib.osType().match(/^Win/)) {
extPath = await toolLib.extractZip(downloadPath);
}
else {
extPath = await toolLib.extractTar(downloadPath);
}
// cache tool
let cachedToolName = getCachedToolName(packageType);
console.log(taskLib.loc("CachingTool"));
let cachedDir = await toolLib.cacheDir(extPath, cachedToolName, version);
console.log(taskLib.loc("SuccessfullyInstalled", packageType, version));
return cachedDir;
}
示例9: downloadHelm
export async function downloadHelm(version?: string): Promise<string> {
if (!version) version = await getStableHelmVersion();
var cachedToolpath = toolLib.findLocalTool(helmToolName, version);
if (!cachedToolpath) {
try {
var helmDownloadPath = await toolLib.downloadTool(getHelmDownloadURL(version), helmToolName + "-" + version + "-" + uuidV4() + ".zip");
} catch (exception) {
throw new Error(tl.loc("HelmDownloadFailed", getHelmDownloadURL(version), exception));
}
var unzipedHelmPath = await toolLib.extractZip(helmDownloadPath);
cachedToolpath = await toolLib.cacheDir(unzipedHelmPath, helmToolName, version);
}
var helmpath = findHelm(cachedToolpath);
if (!helmpath) {
throw new Error(tl.loc("HelmNotFoundInFolder", cachedToolpath))
}
fs.chmodSync(helmpath, "777");
return helmpath;
}