Esempio n. 1
0
/**
 * Run a tool with `sudo` on Linux and macOS
 * Precondition: `toolName` executable is in PATH
 */
function sudo(toolName: string, platform: Platform): ToolRunner {
    if (platform === Platform.Windows) {
        return task.tool(toolName);
    } else {
        const toolPath = task.which(toolName);
        return task.tool('sudo').line(toolPath);
    }
}
Esempio n. 2
0
    private detectMachineOS(): string[] {
        let osSuffix = [];
        let scriptRunner: trm.ToolRunner;

        try {
            console.log(tl.loc("DetectingPlatform"));
            if (tl.osType().match(/^Win/)) {
                let escapedScript = path.join(this.getCurrentDir(), 'externals', 'get-os-platform.ps1').replace(/'/g, "''");
                let command = `& '${escapedScript}'`

                let powershellPath = tl.which('powershell', true);
                scriptRunner = tl.tool(powershellPath)
                    .line('-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command')
                    .arg(command);
            }
            else {
                let scriptPath = path.join(this.getCurrentDir(), 'externals', 'get-os-distro.sh');
                this.setFileAttribute(scriptPath, "777");

                scriptRunner = tl.tool(tl.which(scriptPath, true));
            }

            let result: trm.IExecSyncResult = scriptRunner.execSync();

            if (result.code != 0) {
                throw tl.loc("getMachinePlatformFailed", result.error ? result.error.message : result.stderr);
            }

            let output: string = result.stdout;

            let index;
            if ((index = output.indexOf("Primary:")) >= 0) {
                let primary = output.substr(index + "Primary:".length).split(os.EOL)[0];
                osSuffix.push(primary);
                console.log(tl.loc("PrimaryPlatform", primary));
            }

            if ((index = output.indexOf("Legacy:")) >= 0) {
                let legacy = output.substr(index + "Legacy:".length).split(os.EOL)[0];
                osSuffix.push(legacy);
                console.log(tl.loc("LegacyPlatform", legacy));
            }

            if (osSuffix.length == 0) {
                throw tl.loc("CouldNotDetectPlatform");
            }
        }
        catch (ex) {
            throw tl.loc("FailedInDetectingMachineArch", JSON.stringify(ex));
        }

        return osSuffix;
    }
    public createComposeCommand(): tr.ToolRunner {
        var command = tl.tool(this.dockerComposePath);

        command.arg(["-f", this.dockerComposeFile]);

        var basePath = path.dirname(this.dockerComposeFile);
        this.additionalDockerComposeFiles.forEach(file => {
            // If the path is relative, resolve it
            if (file.indexOf("/") !== 0) {
                file = path.join(basePath, file);
            }
            if (this.requireAdditionalDockerComposeFiles || tl.exist(file)) {
                command.arg(["-f", file]);
            }
        });
        if (this.finalComposeFile) {
            command.arg(["-f", this.finalComposeFile]);
        }

        if (this.projectName) {
            command.arg(["-p", this.projectName]);
        }

        return command;
    }
Esempio n. 4
0
async function executePythonTool(commandToExecute){
    var pythonTool = tl.tool(pythonToolPath);
    pythonTool.on('stderr', function (data) {
        error += (data || '').toString();
    });
    await pythonTool.line(commandToExecute).exec();
}
Esempio n. 5
0
 public createCommand(): tr.ToolRunner {
     var command = tl.tool(this.kubectlPath);
     if(this.kubeconfigFile)
     {
         command.arg("--kubeconfig");
         command.arg(this.kubeconfigFile);
     }
     return command;
 }
Esempio n. 6
0
export async function updateConda(condaRoot: string, platform: Platform): Promise<void> {
    try {
        const conda = task.tool('conda');
        conda.line('update --name base conda --yes');
        await conda.exec();
    } catch (e) {
        // Best effort
    }
}
Esempio n. 7
0
function getVSTestConsole15Path(): string {
    const vswhereTool = tl.tool(path.join(__dirname, 'vswhere.exe'));
    vswhereTool.line('-version [15.0,16.0) -latest -products * -requires Microsoft.VisualStudio.PackageGroup.TestTools.Core -property installationPath');
    let vsPath = vswhereTool.execSync().stdout;
    tl.debug('Visual Studio 15.0 or higher installed path: ' + vsPath);
    vsPath = utils.Helper.trimString(vsPath);
    if (!utils.Helper.isNullOrWhitespace(vsPath)) {
        return path.join(vsPath, 'Common7', 'IDE', 'CommonExtensions', 'Microsoft', 'TestWindow');
    }
    return null;
}
 public createCommand(): tr.ToolRunner {
     var command = tl.tool(this.dockerPath);
     if (this.hostUrl) {
         command.arg(["-H", this.hostUrl]);
         command.arg("--tls");
         command.arg("--tlscacert='" + this.caPath + "'");
         command.arg("--tlscert='" + this.certPath + "'");
         command.arg("--tlskey='" + this.keyPath + "'");
     }
     return command;
 }
Esempio n. 9
0
function getNPMPrefix(): string {
    if (getNPMPrefix["value"]) {
        return getNPMPrefix["value"];
    }

    const tool = tl.tool(tl.which("npm", true));
    tool.arg("prefix");
    tool.arg("-g");

    return (getNPMPrefix["value"] = tool.execSync().stdout.trim());
}
Esempio n. 10
0
function installBower(): Promise<void> {
    const tool = tl.tool(tl.which("npm", true));
    tool.arg("install");
    tool.arg("-g");
    tool.arg("bower");

    return tool.exec().then(() => {
        bower = findGlobalBower();
        if (!bower) {
            tl.setResult(tl.TaskResult.Failed, tl.loc("NpmGlobalNotInPath"));
            throw new Error("NPM_GLOBAL_PREFIX_NOT_IN_PATH");
        }
    });
}