當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript tool.findLocalTool函數代碼示例

本文整理匯總了TypeScript中vsts-task-tool-lib/tool.findLocalTool函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript findLocalTool函數的具體用法?TypeScript findLocalTool怎麽用?TypeScript findLocalTool使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了findLocalTool函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getNode

export async function getNode(versionSpec: string, checkLatest: boolean) {
    if (toolLib.isExplicitVersion(versionSpec)) {
        checkLatest = false; // check latest doesn't make sense when explicit version
    }

    // check cache
    let toolPath: string;
    if (!checkLatest) {
        toolPath = toolLib.findLocalTool('node', versionSpec);
    }

    if (!toolPath) {
        let version: string;
        if (toolLib.isExplicitVersion(versionSpec)) {
            // version to download
            version = versionSpec;
        }
        else {
            // query nodejs.org for a matching version
            version = await queryLatestMatch(versionSpec);
            if (!version) {
                throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
            }

            // check cache
            toolPath = toolLib.findLocalTool('node', version)
        }

        if (!toolPath) {
            // download, extract, cache
            toolPath = await acquireNode(version);
        }
    }

    //
    // a tool installer initimately knows details about the layout of that tool
    // for example, node binary is in the bin folder after the extract on Mac/Linux.
    // layouts could change by version, by platform etc... but that's the tool installers job
    //
    if (osPlat != 'win32') {
        toolPath = path.join(toolPath, 'bin');
    }

    //
    // prepend the tools path. instructs the agent to prepend for future tasks
    //
    toolLib.prependPath(toolPath);
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:48,代碼來源:installer.ts

示例2: useRubyVersion

export async function useRubyVersion(parameters: TaskParameters, platform: Platform): Promise<void> {
    const toolName: string = 'Ruby';
    const installDir: string | null = tool.findLocalTool(toolName, parameters.versionSpec);
    if (!installDir) {
        // Fail and list available versions
        throw new Error([
            task.loc('VersionNotFound', parameters.versionSpec),
            task.loc('ListAvailableVersions'),
            tool.findLocalToolVersions('Ruby')
        ].join(os.EOL));
    }

    const toolPath: string = path.join(installDir, 'bin');
    if (platform !== Platform.Windows) {
        // replace the default
        const dest: string = '/usr/bin/ruby';
        if (fs.existsSync(dest)) {
            task.debug('removing ' + dest);
            fs.unlinkSync(dest);
        }
        fs.symlinkSync(path.join(toolPath, 'ruby'), dest);
    }

    task.setVariable('rubyLocation', toolPath);
    if (parameters.addToPath) {
        tool.prependPath(toolPath);
    }
}
開發者ID:bleissem,項目名稱:vsts-tasks,代碼行數:28,代碼來源:userubyversion.ts

示例3: useRubyVersion

export async function useRubyVersion(parameters: TaskParameters, platform: Platform): Promise<void> {
    const toolName: string = 'Ruby';
    const installDir: string | null = tool.findLocalTool(toolName, parameters.versionSpec);
    if (!installDir) {
        // Fail and list available versions
        throw new Error([
            task.loc('VersionNotFound', parameters.versionSpec),
            task.loc('ListAvailableVersions', task.getVariable('Agent.ToolsDirectory')),
            tool.findLocalToolVersions('Ruby'),
            task.loc('ToolNotFoundMicrosoftHosted', 'Ruby', 'https://aka.ms/hosted-agent-software'),
            task.loc('ToolNotFoundSelfHosted', 'Ruby', 'https://go.microsoft.com/fwlink/?linkid=2005989')
        ].join(os.EOL));
    }

    const toolPath: string = path.join(installDir, 'bin');
    if (platform !== Platform.Windows) {
        // Ruby / Gem heavily use the '#!/usr/bin/ruby' to find ruby, so this task needs to
        // replace that version of ruby so all the correct version of ruby gets selected
        // replace the default
        const dest: string = '/usr/bin/ruby';
        task.execSync('sudo', `ln -sf ${path.join(toolPath, 'ruby')} ${dest}`); // replace any existing
    }

    task.setVariable('rubyLocation', toolPath);
    if (parameters.addToPath) {
        tool.prependPath(toolPath);
    }
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:28,代碼來源:userubyversion.ts

示例4: installVsTestPlatformToolFromNetworkShare

    // Installs the test platform from a network share path provided by the user. The path should point to a .nupkg file.
    public async installVsTestPlatformToolFromNetworkShare(netSharePath: string) {
        let vstestPlatformInstalledLocation;
        let packageSource;

        // Remove all double quotes from the path.
        netSharePath = netSharePath.replace(/["]+/g, '');

        tl.debug(`Attempting to fetch the vstest platform from the specified network share path ${netSharePath}.`);

        if (helpers.pathExistsAsFile(netSharePath)) {
            packageSource = path.dirname(netSharePath);
        } else {
            ci.addToConsolidatedCi('failureReason', constants.packageFileDoesNotExist);
            throw new Error(tl.loc('SpecifiedFileDoesNotExist', netSharePath));
        }

        const fileName = path.basename(netSharePath);
        const versionExtractionRegex = constants.versionExtractionRegex;
        const regexMatches = versionExtractionRegex.exec(fileName);

        if (!regexMatches || regexMatches.length !== 2) {
            ci.addToConsolidatedCi('failureReason', constants.unexpectedPackageFileName);
            throw new Error(tl.loc('UnexpectedFileName', fileName));
        }
        const testPlatformVersion = regexMatches[1];
        ci.addToConsolidatedCi('testPlatformVersion', testPlatformVersion);

        // If the version provided is not an explicit version (ie contains containing wildcards) then throw
        if (!toolLib.isExplicitVersion(testPlatformVersion)) {
            ci.publishEvent('InvalidVersionSpecified', { version: testPlatformVersion } );
            ci.addToConsolidatedCi('failureReason', constants.notExplicitVersion);
            throw new Error(tl.loc('ProvideExplicitVersion', testPlatformVersion));
        }

        console.log(tl.loc('ParsedVersion', testPlatformVersion));
        tl.debug(`Looking for version ${testPlatformVersion} in the tools cache.`);
        startTime = perf();

        // Check cache for the specified version
        vstestPlatformInstalledLocation = toolLib.findLocalTool(constants.toolFolderName, testPlatformVersion);

        ci.addToConsolidatedCi('cacheLookupTime', perf() - startTime);

        // If found in the cache then set the tool location and return
        if (!helpers.isNullEmptyOrUndefined(vstestPlatformInstalledLocation)) {
            ci.addToConsolidatedCi('firstCacheLookupSucceeded', 'true');
            helpers.setVsTestToolLocation(vstestPlatformInstalledLocation);
            return;
        }

        ci.addToConsolidatedCi('firstCacheLookupSucceeded', 'false');

        vstestPlatformInstalledLocation = await new NugetDownloadHelper()
            .attemptPackageDownload(packageSource, testPlatformVersion, null);

        // Set the vstest platform tool location for the vstest task to consume
        helpers.setVsTestToolLocation(vstestPlatformInstalledLocation);
    }
開發者ID:shubham90,項目名稱:vsts-tasks,代碼行數:59,代碼來源:networkshareinstaller.ts

示例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));
    }
}
開發者ID:shubham90,項目名稱:vsts-tasks,代碼行數:49,代碼來源:ArtifactToolUtilities.ts

示例6: downloadKubectl

export async function downloadKubectl(version: string) : Promise<string> {
    var cachedToolpath = toolLib.findLocalTool(kubectlToolName, version);
    if(!cachedToolpath) {
        try {
                var KubectlDownloadPath = await toolLib.downloadTool(getkubectlDownloadURL(version)); 
        } catch(exception) {
            throw new Error(tl.loc("DownloadKubectlFailedFromLocation", getkubectlDownloadURL(version), exception));
        }

        cachedToolpath = await toolLib.cacheFile(KubectlDownloadPath, kubectlToolName + getExecutableExtention() , kubectlToolName, version);
    }
    
    var kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtention());
    fs.chmodSync(kubectlPath, "777");
    return kubectlPath;
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:16,代碼來源:kubectlutility.ts

示例7: getGo

async function getGo(version: string) {
    // check cache
    let toolPath: string;
    toolPath = toolLib.findLocalTool('go', fixVersion(version));

    if (!toolPath) {
        // download, extract, cache
        toolPath = await acquireGo(version);
        tl.debug("Go tool is cached under " + toolPath);
    }

    setGoEnvironmentVariables(toolPath);

    toolPath = path.join(toolPath, 'bin');
    //
    // prepend the tools path. instructs the agent to prepend for future tasks
    //
    toolLib.prependPath(toolPath);
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:19,代碼來源:gotool.ts

示例8: attemptPackageDownload

    // Attemps to download the package and on failure looks for the latest stable version already present in the cache
    public async attemptPackageDownload(packageSource: string, testPlatformVersion: string, nugetConfigFilePath: string) : Promise<string> {
        let vstestPlatformInstalledLocation;
        try {
            tl.debug(`Could not find ${constants.packageId}.${testPlatformVersion} in the tools cache. Fetching it from nuget.`);

            // Download the required version and cache it
            vstestPlatformInstalledLocation = await this.acquireAndCacheVsTestPlatformNuget(packageSource,
                testPlatformVersion, nugetConfigFilePath);

        } catch (error) {
            tl.error(tl.loc('TestPlatformDownloadFailed', testPlatformVersion, error));

            if ((tl.getInput(constants.packageFeedSelector) === constants.nugetOrg || tl.getInput(constants.packageFeedSelector) === constants.customFeed)
                && tl.getInput(constants.versionSelector) === constants.specificVersion) {
                return null;
            }

            console.log(tl.loc('LatestStableCached'));
            testPlatformVersion = 'x';

            ci.addToConsolidatedCi('downloadSucceeded', 'false');
            ci.publishEvent('DownloadFailed', { action: 'getLatestAvailableInCache', error: error } );
            startTime = perf();

            // Download failed, look for the latest version available in the cache
            vstestPlatformInstalledLocation = toolLib.findLocalTool(constants.toolFolderName, testPlatformVersion);

            ci.addToConsolidatedCi('secondCacheLookupTime', perf() - startTime);

            // No version found in cache, fail the task
            if (!vstestPlatformInstalledLocation || vstestPlatformInstalledLocation === 'undefined') {
                ci.addToConsolidatedCi('secondCacheLookupSucceeded', 'false');
                ci.addToConsolidatedCi('failureReason', constants.downloadFailed);
                tl.error(tl.loc('NoPackageFoundInCache'));
                throw new Error(tl.loc('FailedToAcquireTestPlatform'));
            }

            ci.addToConsolidatedCi('secondCacheLookupSucceeded', 'true');
        }

        return vstestPlatformInstalledLocation;
    }
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:43,代碼來源:nugetdownloadhelper.ts

示例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;
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:21,代碼來源:helmutility.ts

示例10: usePythonVersion

export async function usePythonVersion(parameters: Readonly<TaskParameters>, platform: Platform): Promise<void> {
    // Python's prelease versions look like `3.7.0b2`.
    // This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
    // If the version spec contains prerelease versions, we need to convert them to the semantic version equivalent
    const semanticVersionSpec = pythonVersionToSemantic(parameters.versionSpec);
    task.debug(`Semantic version spec of ${parameters.versionSpec} is ${semanticVersionSpec}`);

    const installDir: string | null = tool.findLocalTool('Python', semanticVersionSpec, parameters.architecture);
    if (!installDir) {
        // Fail and list available versions
        const x86Versions = tool.findLocalToolVersions('Python', 'x86')
            .map(s => `${s} (x86)`)
            .join(os.EOL);

        const x64Versions = tool.findLocalToolVersions('Python', 'x64')
            .map(s => `${s} (x64)`)
            .join(os.EOL);

        throw new Error([
            task.loc('VersionNotFound', parameters.versionSpec),
            task.loc('ListAvailableVersions'),
            x86Versions,
            x64Versions
        ].join(os.EOL));
    }

    task.setVariable('pythonLocation', installDir);
    if (parameters.addToPath) {
        toolUtil.prependPathSafe(installDir);

        // Make sure Python's "bin" directories are in PATH.
        // Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
        // This is where pip is, along with anything that pip installs.
        // There is a seperate directory for `pip install --user`.
        //
        // For reference, these directories are as follows:
        //   macOS / Linux:
        //      <sys.prefix>/bin (by default /usr/local/bin, but not on hosted agents -- see the `else`)
        //      (--user) ~/.local/bin
        //   Windows:
        //      <Python installation dir>\Scripts
        //      (--user) %APPDATA%\Python\PythonXY\Scripts
        // See https://docs.python.org/3/library/sysconfig.html
        if (platform === Platform.Windows) {
            // On Windows, these directories do not get added to PATH, so we will add them ourselves.
            const scriptsDir = path.join(installDir, 'Scripts');
            toolUtil.prependPathSafe(scriptsDir);

            // Add --user directory
            // `installDir` from tool cache should look like $AGENT_TOOLSDIRECTORY/Python/<semantic version>/x64/
            // So if `findLocalTool` succeeded above, we must have a conformant `installDir`
            const version = path.basename(path.dirname(installDir));
            const major = semver.major(version);
            const minor = semver.minor(version);

            const userScriptsDir = path.join(process.env['APPDATA'], 'Python', `Python${major}${minor}`, 'Scripts');
            toolUtil.prependPathSafe(userScriptsDir);
        } else {
            // On Linux and macOS, tools cache should be set up so that each Python version has its own "bin" directory.
            // We do this so that the tool cache can just be dropped on an agent with minimal installation (no copying to /usr/local).
            // This allows us side-by-side the same minor version of Python with different patch versions or architectures (since Python uses /usr/local/lib/python3.6, etc.).
            toolUtil.prependPathSafe(path.join(installDir, 'bin'));

            // On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
        }
    }
}
開發者ID:bleissem,項目名稱:vsts-tasks,代碼行數:67,代碼來源:usepythonversion.ts


注:本文中的vsts-task-tool-lib/tool.findLocalTool函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。