export async function runTfx()

in BuildTasks/Common/Common.ts [175:210]


export async function runTfx(cmd: (tfx: ToolRunner) => void) : Promise<boolean> {
    let tfx: ToolRunner;
    let tfxPath: string;

    const tryRunCmd = async (tfx: ToolRunner) => {
        try {
            // Set working folder
            const cwd = tl.getInput("cwd", false);
            if (cwd) {
                tl.cd(cwd);
            }

            cmd(tfx);
            return true;
        }
        catch (err) {
            tl.setResult(tl.TaskResult.Failed, `Error running task: ${err}`);
            return false;
        }
    };

    const tfxInstallerPath = tl.getVariable("__tfxpath");
    if (tfxInstallerPath)
    {
        tfxPath = tl.which(path.join(tfxInstallerPath, "/tfx"));
    }

    if (tfxPath) {
        tl.debug(`using: ${tfxPath}`);
        tfx = new trl.ToolRunner(tfxPath);
        await tryRunCmd(tfx);
        return;
    }

    tl.setResult(tl.TaskResult.Failed, "Could not find tfx. To resolve, add the 'Use Node CLI for Azure DevOps' task to your pipeline before this task.");
}