How to use the azure-pipelines-tool-lib/tool.cacheDir function in azure-pipelines-tool-lib

To help you get started, we’ve selected a few azure-pipelines-tool-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / azure-pipelines-tasks / Tasks / GoToolV0 / gotool.ts View on Github external
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);
}
github microsoft / azure-devops-extension-tasks / BuildTasks / TfxInstaller / TfxInstaller.ts View on Github external
throw new Error('Expected Agent.TempDirectory to be set');
        }
        extPath = path.join(extPath, 'tfx'); // use as short a path as possible due to nested node_modules folders

        taskLib.mkdirP(path.join(extPath));
        const npmRunner = new tr.ToolRunner("npm");
        npmRunner.arg(["install", "tfx-cli@" + version, "--prefix", extPath]);

        const result = npmRunner.execSync({ failOnStdErr: false, silent: true, ignoreReturnCode: false} as tr.IExecOptions);
        if (result.code === 0)
        {
            if (os.platform() === "win32")
            {
                fs.unlinkSync(path.join(extPath, "/tfx"));
            }
            return await toolLib.cacheDir(extPath, 'tfx', version);
        }
    }
    catch {
        return Promise.reject(new Error("Failed to install tfx"));
    }
}
github microsoft / azure-pipelines-tasks / Tasks / UseGoV1 / installer.ts View on Github external
throw new Error(tl.loc('TempDirNotSet'));
    }

    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
    //
    const toolRoot = path.join(extPath, "go");
    version = normalizeVersion(version);
    return await toolLib.cacheDir(toolRoot, 'go', version);
}
github microsoft / azure-pipelines-artifact-caching-tasks / Tasks / Common / packaging-common / ArtifactToolUtilities.ts View on Github external
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.warning(err);
        // TODO: Should return null?
        // tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToGetArtifactTool", err));
        return null;
    }
}
github rdagumampan / yuniql / yuniql-azure-pipelines / src / install / installer.ts View on Github external
}

            const downloadBaseUrl = 'https://github.com/rdagumampan/yuniql/releases/download'
            const downloadUrl = downloadBaseUrl + '/' + version + '/' + packageFileName;
            console.log('yuniql/var_downloadUrl: ' + downloadUrl);

            const temp: string = await toolLib.downloadTool(downloadUrl);
            console.log('yuniql/var_temp: ' + temp);

            //extract assemblies
            const extractRoot: string = await toolLib.extractZip(temp);
            console.log('yuniql/var_extractRoot: ' + extractRoot);

            //cache assemblies
            if (version != 'latest') {
                toolLib.cacheDir(extractRoot, "yuniql", version);
            } else {
                //use v0.0.0 as placeholder for latest version
                //TODO: always replace the current cached version for now
                toolLib.cleanVersion('v0.0.0');
                toolLib.cacheDir(extractRoot, "yuniql", 'v0.0.0');
            }

            //append PATH
            toolLib.prependPath(extractRoot);
        }
    }
    catch (error) {
        console.log('yuniql/error: ' + error.message);
        taskLib.setResult(taskLib.TaskResult.Failed, error.message);
    }
}
github microsoft / azure-pipelines-tasks / Tasks / Common / func-tools-common / functoolsutility.ts View on Github external
export async function downloadFuncTools(version: string): Promise {
        let cachedToolpath = toolLib.findLocalTool(funcToolName, version);
        
        if (!cachedToolpath) {
            const downloadUrl = getDownloadUrl(version);
            let downloadPath;
            try {
                downloadPath = await toolLib.downloadTool(downloadUrl);
            }
            catch (ex) {
                throw new Error(tl.loc('FuncDownloadFailed', downloadUrl, ex));
            }
            
            tl.debug('Extracting the downloaded func tool zip..');
            const unzippedFuncPath = await toolLib.extractZip(downloadPath);
            cachedToolpath = await toolLib.cacheDir(unzippedFuncPath, funcToolName, version);
            console.log(tl.loc("SuccessfullyDownloaded", version, cachedToolpath));
        } else {
            console.log(tl.loc("VersionAlreadyInstalled", version, cachedToolpath));
        }

        const funcPath = path.join(cachedToolpath, funcToolName + getExecutableExtension());
        fs.chmodSync(funcPath, '777');
        return funcPath;
}