How to use azure-pipelines-tool-lib - 10 common examples

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 / UsePythonV1 / usepythonversion.ts View on Github external
async function useCpythonVersion(parameters: Readonly, platform: Platform): Promise {
    const desugaredversion = desugarDevVersion(parameters.version);
    const semanticversion: string = pythonVersionToSemantic(desugaredversion);
    task.debug(`Semantic version spec of ${parameters.version} is ${semanticversion}`);

    const installDir: string | null = tool.findLocalTool('Python', semanticversion, parameters.architecture);

    console.log('INSTALL DIR - ' + installDir);

    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.version, parameters.architecture),
            task.loc('ListAvailableVersions', task.getVariable('Agent.ToolsDirectory')),
github rdagumampan / yuniql / yuniql-azure-pipelines / src / run / runyuniql.ts View on Github external
console.log('yuniql/input_additionalArguments: ' + additionalArguments);

        console.log('yuniql/var_osPlat: ' + osPlat);
        console.log('yuniql/var_osArch: ' + osArch);

        //picksup the version downloaded from install task
        let versionLocation: string = '';
        if (toolLib.isExplicitVersion(versionSpec)) {
            versionLocation = versionSpec;
        } else {
            //use v0.0.0 as placeholder for latest version
            versionLocation = 'v0.0.0'
        }

        if (osPlat == 'win32') {
            var yuniqlBasePath = path.join(toolLib.findLocalTool('yuniql', versionLocation));
            console.log('yuniql/var_yuniqlBasePath: ' + yuniqlBasePath);

            var yuniqlExecFilePath = path.join(yuniqlBasePath, 'yuniql.exe');
            console.log('yuniql/var_yuniqlExecFilePath: ' + yuniqlExecFilePath);

            //set the plugin path
            // var pluginsPath = path.join(yuniqlBasePath, '.plugins');
            // console.log('var_pluginsPath: ' + pluginsPath);

            //builds up the arguments structure
            let yuniql = new tr.ToolRunner(yuniqlExecFilePath);
            yuniql.arg('run');

            // yuniql.arg('--plugins-path');
            // yuniql.arg(pluginsPath);
github microsoft / azure-pipelines-tasks / Tasks / DotNetCoreInstallerV1 / dotnetcoreinstaller.ts View on Github external
console.log(tl.loc("ToolToInstall", packageType, versionSpec));
    var versionSpecParts = new VersionParts(versionSpec);

    let versionFetcher = new DotNetCoreVersionFetcher();
    let versionInfo: VersionInfo = await versionFetcher.getVersionInfo(versionSpecParts.versionSpec, packageType, includePreviewVersions);
    if (!versionInfo) {
        throw tl.loc("MatchingVersionNotFound", versionSpecParts.versionSpec);
    }

    let dotNetCoreInstaller = new VersionInstaller(packageType, installationPath);
    if (!dotNetCoreInstaller.isVersionInstalled(versionInfo.getVersion())) {
        await dotNetCoreInstaller.downloadAndInstall(versionInfo, versionFetcher.getDownloadUrl(versionInfo));
    }

    toolLib.prependPath(installationPath);

    // By default disable Multi Level Lookup unless user wants it enabled.
    let  performMultiLevelLookup = tl.getBoolInput("performMultiLevelLookup", false);
    tl.setVariable("DOTNET_MULTILEVEL_LOOKUP", !performMultiLevelLookup ? "0" : "1");

    // Add dot net tools path to "PATH" environment variables, so that tools can be used directly.
    addDotNetCoreToolPath();

    // Set DOTNET_ROOT for dotnet core Apphost to find runtime since it is installed to a non well-known location.
    tl.setVariable('DOTNET_ROOT', installationPath);
}
github microsoft / azure-pipelines-tasks / Tasks / DotNetCoreInstallerV1 / versioninstaller.ts View on Github external
public async downloadAndInstall(versionInfo: VersionInfo, downloadUrl: string): Promise {
        if (!versionInfo || !versionInfo.getVersion() || !downloadUrl || !url.parse(downloadUrl)) {
            throw tl.loc("VersionCanNotBeDownloadedFromUrl", versionInfo, downloadUrl);
        }

        let version = versionInfo.getVersion();

        try {
            try {
                var downloadPath = await toolLib.downloadTool(downloadUrl)
            }
            catch (ex) {
                throw tl.loc("CouldNotDownload", downloadUrl, ex);
            }

            // Extract
            console.log(tl.loc("ExtractingPackage", downloadPath));
            try {
                var extPath = tl.osType().match(/^Win/) ? await toolLib.extractZip(downloadPath) : await toolLib.extractTar(downloadPath);
            }
            catch (ex) {
                throw tl.loc("FailedWhileExtractingPacakge", ex);
            }

            // Copy folders
            tl.debug(tl.loc("CopyingFoldersIntoPath", this.installationPath));
github microsoft / azure-pipelines-tasks / Tasks / DotNetCoreInstallerV1 / versioninstaller.ts View on Github external
}

        let version = versionInfo.getVersion();

        try {
            try {
                var downloadPath = await toolLib.downloadTool(downloadUrl)
            }
            catch (ex) {
                throw tl.loc("CouldNotDownload", downloadUrl, ex);
            }

            // Extract
            console.log(tl.loc("ExtractingPackage", downloadPath));
            try {
                var extPath = tl.osType().match(/^Win/) ? await toolLib.extractZip(downloadPath) : await toolLib.extractTar(downloadPath);
            }
            catch (ex) {
                throw tl.loc("FailedWhileExtractingPacakge", ex);
            }

            // Copy folders
            tl.debug(tl.loc("CopyingFoldersIntoPath", this.installationPath));
            var allRootLevelEnteriesInDir: string[] = tl.ls("", [extPath]).map(name => path.join(extPath, name));
            var directoriesTobeCopied: string[] = allRootLevelEnteriesInDir.filter(path => fs.lstatSync(path).isDirectory());
            directoriesTobeCopied.forEach((directoryPath) => {
                tl.cp(directoryPath, this.installationPath, "-rf", false);
            });

            // Copy files
            try {
                if (this.packageType == utils.Constants.sdk && this.isLatestInstalledVersion(version)) {
github microsoft / azure-pipelines-tasks / Tasks / UseDotNetV2 / versioninstaller.ts View on Github external
throw tl.loc("VersionCanNotBeDownloadedFromUrl", versionInfo, downloadUrl);
        }
        let version = versionInfo.getVersion();

        try {
            try {
                var downloadPath = await toolLib.downloadTool(downloadUrl)
            }
            catch (ex) {
                throw tl.loc("CouldNotDownload", downloadUrl, ex);
            }

            // Extract
            console.log(tl.loc("ExtractingPackage", downloadPath));
            try {
                var extPath = tl.osType().match(/^Win/) ? await toolLib.extractZip(downloadPath) : await toolLib.extractTar(downloadPath);
            }
            catch (ex) {
                throw tl.loc("FailedWhileExtractingPacakge", ex);
            }

            // Copy folders
            tl.debug(tl.loc("CopyingFoldersIntoPath", this.installationPath));
            var allRootLevelEnteriesInDir: string[] = tl.ls("", [extPath]).map(name => path.join(extPath, name));
            var directoriesTobeCopied: string[] = allRootLevelEnteriesInDir.filter(path => fs.lstatSync(path).isDirectory());
            directoriesTobeCopied.forEach((directoryPath) => {
                tl.cp(directoryPath, this.installationPath, "-rf", false);
            });

            // Copy files
            try {
                if (this.packageType == utils.Constants.sdk && this.isLatestInstalledVersion(version)) {
github rdagumampan / yuniql / yuniql-azure-pipelines / src / run / runyuniql.ts View on Github external
console.log('yuniql/input_version: ' + versionSpec);
        console.log('yuniql/input_workspacePath: ' + workspacePath);
        console.log('yuniql/input_connectionString: ' + connectionString);
        console.log('yuniql/input_targetPlatform: ' + targetPlatform);
        console.log('yuniql/input_autoCreateDatabase: ' + autoCreateDatabase);
        console.log('yuniql/input_targetVersion: ' + targetVersion);
        console.log('yuniql/input_tokenKeyValuePair: ' + tokenKeyValuePair);
        console.log('yuniql/input_delimiter: ' + delimiter);
        console.log('yuniql/input_additionalArguments: ' + additionalArguments);

        console.log('yuniql/var_osPlat: ' + osPlat);
        console.log('yuniql/var_osArch: ' + osArch);

        //picksup the version downloaded from install task
        let versionLocation: string = '';
        if (toolLib.isExplicitVersion(versionSpec)) {
            versionLocation = versionSpec;
        } else {
            //use v0.0.0 as placeholder for latest version
            versionLocation = 'v0.0.0'
        }

        if (osPlat == 'win32') {
            var yuniqlBasePath = path.join(toolLib.findLocalTool('yuniql', versionLocation));
            console.log('yuniql/var_yuniqlBasePath: ' + yuniqlBasePath);

            var yuniqlExecFilePath = path.join(yuniqlBasePath, 'yuniql.exe');
            console.log('yuniql/var_yuniqlExecFilePath: ' + yuniqlExecFilePath);

            //set the plugin path
            // var pluginsPath = path.join(yuniqlBasePath, '.plugins');
            // console.log('var_pluginsPath: ' + pluginsPath);
github rdagumampan / yuniql / yuniql-azure-pipelines / src / install / installer.ts View on Github external
export async function getYuniql(versionSpec: string, checkLatest: boolean) {
    try {
        console.log('yuniql/var_osPlat: ' + osPlat);
        console.log('yuniql/var_osArch: ' + osArch);

        // when version is explicit, we dont check the latest
        let version: string = '';
        if (toolLib.isExplicitVersion(versionSpec)) {
            checkLatest = false;
            console.log('yuniql/var_isExplicitVersion: true');
            console.log('yuniql/var_checkLatest: false');
        }

        // when version is explicit, we check the cache first
        let toolPath: string = '';
        if (!checkLatest) {
            toolPath = toolLib.findLocalTool('yuniql', versionSpec);
        }

        // when cached version doesnt exists, we download a fresh copy
        if (!toolPath) {
            //when version is explicit, use the version specified, else we acquire latest version
            if (toolLib.isExplicitVersion(versionSpec)) {
                version = versionSpec;
github microsoft / azure-pipelines-tasks / Tasks / UsePythonV1 / usepythonversion.ts View on Github external
async function useCpythonVersion(parameters: Readonly, platform: Platform): Promise {
    const desugaredversion = desugarDevVersion(parameters.version);
    const semanticversion: string = pythonVersionToSemantic(desugaredversion);
    task.debug(`Semantic version spec of ${parameters.version} is ${semanticversion}`);

    const installDir: string | null = tool.findLocalTool('Python', semanticversion, parameters.architecture);

    console.log('INSTALL DIR - ' + installDir);

    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.version, parameters.architecture),
            task.loc('ListAvailableVersions', task.getVariable('Agent.ToolsDirectory')),
            x86Versions,
            x64Versions,
            task.loc('ToolNotFoundMicrosoftHosted', 'Python', 'https://aka.ms/hosted-agent-software'),
            task.loc('ToolNotFoundSelfHosted', 'Python', 'https://go.microsoft.com/fwlink/?linkid=871498')
        ].join(os.EOL));
    }
github microsoft / azure-pipelines-tasks / Tasks / UsePythonV1 / usepythonversion.ts View on Github external
async function useCpythonVersion(parameters: Readonly, platform: Platform): Promise {
    const desugaredversion = desugarDevVersion(parameters.version);
    const semanticversion: string = pythonVersionToSemantic(desugaredversion);
    task.debug(`Semantic version spec of ${parameters.version} is ${semanticversion}`);

    const installDir: string | null = tool.findLocalTool('Python', semanticversion, parameters.architecture);

    console.log('INSTALL DIR - ' + installDir);

    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.version, parameters.architecture),
            task.loc('ListAvailableVersions', task.getVariable('Agent.ToolsDirectory')),
            x86Versions,
            x64Versions,
            task.loc('ToolNotFoundMicrosoftHosted', 'Python', 'https://aka.ms/hosted-agent-software'),
            task.loc('ToolNotFoundSelfHosted', 'Python', 'https://go.microsoft.com/fwlink/?linkid=871498')
        ].join(os.EOL));
    }

    task.setVariable('pythonLocation', installDir);

    // Append to path