当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript task.execSync函数代码示例

本文整理汇总了TypeScript中azure-pipelines-task-lib/task.execSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript execSync函数的具体用法?TypeScript execSync怎么用?TypeScript execSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了execSync函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setupIotedgedev

  public static setupIotedgedev(): void {
    try {
      let result = tl.execSync(`${Constants.iotedgedev}`, `--version`, Constants.execSyncSilentOption);
      if (result.code === 0) {
        console.log(tl.loc('DependencyAlreadyInstalled', Constants.iotedgedev, result.stdout.substring(result.stdout.indexOf("version"))));
        return;
      }
    } catch (e) {
      // If exception, it means iotedgedev is not installed. Do nothing.
    }

    let cmds: Cmd[] = [];
    let version = Constants.iotedgedevDefaultVersion;
    if (tl.getVariable(Constants.iotedgedevLockVersionKey)) {
      version = tl.getVariable(Constants.iotedgedevLockVersionKey);
    }
    tl.debug(`The specified iotedgedev version is: ${version}`);
    if (tl.osType() === Constants.osTypeLinux) {
      cmds = [
        { path: `sudo`, arg: `apt-get update`, execOption: Constants.execSyncSilentOption },
        { path: `sudo`, arg: `apt-get install -y python-setuptools`, execOption: Constants.execSyncSilentOption },
        { path: `sudo`, arg: `pip install ${Constants.iotedgedev}==${version}`, execOption: Constants.execSyncSilentOption },
      ]
    } else if (tl.osType() === Constants.osTypeWindows) {
      cmds = [
        { path: `pip`, arg: `install ${Constants.iotedgedev}==${version}`, execOption: Constants.execSyncSilentOption },
      ]
    }

    try {
      for (let cmd of cmds) {
        let result = tl.execSync(cmd.path, cmd.arg, cmd.execOption);
        if (result.code !== 0) {
          tl.debug(result.stderr);
        }
      }
    } catch (e) {
      // If exception, record error message to debug
      tl.debug(e);
    }

    let result = tl.execSync(`${Constants.iotedgedev}`, `--version`, Constants.execSyncSilentOption);
    if (result.code === 0) {
      console.log(tl.loc('DependencyInstallSuccess', Constants.iotedgedev, result.stdout.substring(result.stdout.indexOf("version"))));
    } else {
      throw Error(tl.loc('DependencyInstallFail', Constants.iotedgedev));
    }
  }
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:48,代码来源:util.ts

示例2: _extractAdvinst

async function _extractAdvinst(sourceMsi: string): Promise<string> {
  console.log(taskLib.loc("AI_ExtractTool"));

  // Ensure the c:\windows\installer folder exists. MSIEXEC will fail on some clients (E.g. Hosted VS2017)
  // due to the lack of this folder.

  let windowsInstallerFolder = path.join(taskLib.getVariable('windir'), 'Installer');
  if (!taskLib.exist(windowsInstallerFolder)) {
    taskLib.debug(taskLib.loc("AI_CreateInstallerFolder"))
    taskLib.mkdirP(windowsInstallerFolder);
  }

  let advinstWorkFolder = path.join(_getAgentTemp(), 'AdvancedInstaller');
  let msiExtractionPath: string = path.join(advinstWorkFolder, 'resources');
  // Create the work folder, otherwise msiexec will fail because of the log path.
  if (!taskLib.exist(advinstWorkFolder))
    taskLib.mkdirP(advinstWorkFolder);
  let msiLogPath: string = path.join(advinstWorkFolder, 'advinst_install.log');

  let msiexecArguments: string[] = ['/a', sourceMsi, 'TARGETDIR=' + msiExtractionPath, '/qn', '/l*v', msiLogPath];

  let exitCode = taskLib.execSync('msiexec.exe', msiexecArguments).code;
  if (exitCode != 0) {
    taskLib.command('task.uploadfile', {}, msiLogPath);
    return null;
  }
  return msiExtractionPath;
}
开发者ID:Caphyon,项目名称:advinst-vsts-task,代码行数:28,代码来源:AdvinstTool.ts

示例3: _logNpmStartupVariables

async function _logNpmStartupVariables(packagingLocation: pkgLocationUtils.PackagingLocation) {
    try {
        // Log the NPM version
        let version: string;
        try {
            const syncResult: IExecSyncResult = tl.execSync('npm', '--version');
            if (syncResult.stdout) {
                version = syncResult.stdout.trim();
            }
        } catch (err) {
            tl.debug(`Unable to get NPM config info. Err:( ${err} )`);
        }

        // Log the NPM registries
        const command = tl.getInput(NpmTaskInput.Command);
        let npmRegistriesAry: INpmRegistry[];
        const registryUrlAry = [];
        switch (command) {
            case NpmCommand.Install:
            case NpmCommand.Custom:
                npmRegistriesAry = await npmCustom.getCustomRegistries(packagingLocation);
                break;
            case NpmCommand.Publish:
                npmRegistriesAry = [await npmPublish.getPublishRegistry(packagingLocation)];
                break;
        }
        for (const registry of npmRegistriesAry) {
            registryUrlAry.push(registry.url);
        }

        const npmTelem = {
            'command': command,
            'verbose': tl.getInput(NpmTaskInput.Verbose),
            'customRegistry': tl.getInput(NpmTaskInput.CustomRegistry),
            'customFeed': tl.getInput(NpmTaskInput.CustomFeed),
            'customEndpoint': tl.getInput(NpmTaskInput.CustomEndpoint),
            'publishRegistry': tl.getInput(NpmTaskInput.PublishRegistry),
            'publishFeed': tl.getInput(NpmTaskInput.PublishFeed),
            'publishEndpoint': tl.getInput(NpmTaskInput.PublishEndpoint),
            'npmVersion': version,
            'registries': registryUrlAry
        };

        telemetry.emitTelemetry('Packaging', 'npm', npmTelem);
    } catch (err) {
        tl.debug(`Unable to log NPM task telemetry. Err:( ${err} )`);
    }
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:48,代码来源:npm.ts

示例4: debugOsType

 public static debugOsType() {
   let cmd: string[] = null;
   if (tl.osType() === Constants.osTypeWindows) {
     cmd = ['systeminfo', null];
   } else if (tl.osType() === Constants.osTypeLinux) {
     cmd = [`lsb_release`, `-a`];
   }
   if (cmd != null) {
     try {
       let result = tl.execSync(cmd[0], cmd[1], Constants.execSyncSilentOption);
       tl.debug(`OS is ${result.stdout}`);
     } catch (e) {
       tl.debug(`Error happened when fetching os info: ${e.message}`);
     }
   }
 }
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:16,代码来源:util.ts

示例5: registerAdvinst

async function registerAdvinst(toolRoot: string, license: string): Promise<void> {
  if (!license)
    return;

  console.log(taskLib.loc("AI_RegisterTool"))

  let toolVersion: string = fileInfo.getFileVersion(path.join(toolRoot, advinstToolExecutable));
  let registrationCmd: string = "/RegisterCI";
  if (cmpVer.lt(advinstRegVersionSwitch, toolVersion) < 0) {
    registrationCmd = "/Register";
  }

  let execResult = taskLib.execSync(path.join(toolRoot, advinstToolCmdLineUtility), [registrationCmd, license]);
  if (execResult.code != 0) {
    throw new Error(taskLib.loc("AI_RegisterToolFailed", execResult.stdout));
  }
  let licensePath = path.join(taskLib.getVariable('ProgramData'), advinstLicenseSubPath);
  taskLib.checkPath(licensePath, taskLib.loc("AI_AdvinstLicenseFile"));
  taskLib.setVariable('advinst.cleanup', 'true');
}
开发者ID:Caphyon,项目名称:advinst-vsts-task,代码行数:20,代码来源:AdvinstTool.ts

示例6: run

export async function run() {
  let registryAuthenticationToken: RegistryCredential = getRegistryAuthenticationToken();

  let bypassModules = tl.getInput('bypassModules');
  if (bypassModules == null) bypassModules = "";
  tl.debug(`Bypass Modules are: ${bypassModules}`);

  let templateFilePath: string = tl.getPathInput("templateFilePath", true);
  tl.debug(`The template file path is ${templateFilePath}`);
  if (!fs.existsSync(templateFilePath)) {
    throw Error(tl.loc('TemplateFileInvalid', templateFilePath));
  }
  util.setTaskRootPath(path.dirname(templateFilePath));

  util.setupIotedgedev();

  /* 
   * iotedgedev will use registry server url to match which credential to use in push process
   * For example, a normal docker hub credential should have server: https://index.docker.io/v1/ I would like to push to michaeljqzq/repo:0.0.1
   * But if I set CONTAINER_REGISTRY_SERVER=https://index.docker.io/v1/ in environment variable, it won't work.
   * iotedgedev won't load this credential
   * instead, the CONTAINER_REGISTRY_SERVER should be set to michaeljqzq
   * However, "michaeljqzq" is not in the scope of a credential.
   * So here is a work around to login in advanced call to `iotedgedev push` and then logout after everything done.
   */
  tl.execSync(`docker`, `login -u "${registryAuthenticationToken.username}" -p "${registryAuthenticationToken.password}" ${registryAuthenticationToken.serverUrl}`, Constants.execSyncSilentOption)

  let envList = {
    [Constants.iotedgedevEnv.bypassModules]: bypassModules,
    [Constants.iotedgedevEnv.registryServer]: registryAuthenticationToken.serverUrl,
    [Constants.iotedgedevEnv.registryUsername]: registryAuthenticationToken.username,
    [Constants.iotedgedevEnv.registryPassword]: registryAuthenticationToken.password,
  };

  // Pass task variable to sub process
  let tlVariables = tl.getVariables();
  for (let v of tlVariables) {
    // The variables in VSTS build contains dot, need to convert to underscore.
    let name = v.name.replace('.', '_').toUpperCase();
    if (!envList[name]) {
      envList[name] = v.value;
    }
  }

  tl.debug(`Following variables will be passed to the iotedgedev command: ${JSON.stringify(envList)}`);

  try {
    let execOptions: IExecOptions = {
      cwd: tl.cwd(),
      env: envList,
    } as IExecOptions;
    let defaultPlatform = tl.getInput('defaultPlatform', true);
    let command: string = `push --no-build`;
    command += ` --file ${templateFilePath}`;
    command += ` --platform ${defaultPlatform}`;
    await tl.exec(`${Constants.iotedgedev}`, command, execOptions);

    tl.execSync(`docker`, `logout`, Constants.execSyncSilentOption);
    util.createOrAppendDockerCredentials(registryAuthenticationToken);

    let dockerCredentials = util.readDockerCredentials();
    tl.debug(`Number of docker cred passed: ${dockerCredentials.length}`);

    let outputDeploymentJsonPath = tl.getVariable('_' + Constants.outputVariableDeploymentPathKey);
    if (!fs.existsSync(outputDeploymentJsonPath)) {
      tl.debug(`The generated deployment file can't be found in the path: ${outputDeploymentJsonPath}`);
    }else {
      console.log(tl.loc('DeploymentFilePath', outputDeploymentJsonPath));
      let deploymentJson = JSON.parse(fs.readFileSync(outputDeploymentJsonPath, Constants.UTF8));
      // Expand docker credentials
      // Will replace the registryCredentials if the server match
      if (dockerCredentials != undefined && util.getModulesContent(deploymentJson)['$edgeAgent']['properties.desired'].runtime.settings.registryCredentials != undefined) {
        console.log(tl.loc('ExpandingRegistryCredentials'));
        let credentials = util.getModulesContent(deploymentJson)['$edgeAgent']['properties.desired'].runtime.settings.registryCredentials;
        for (let key of Object.keys(credentials)) {
          if (credentials[key].username && (credentials[key].username.startsWith("$") || credentials[key].password.startsWith("$"))) {
            tl.debug(`Going to replace the cred in deployment.json with address: ${credentials[key].address}`);
            for (let dockerCredential of dockerCredentials) {
              if (util.isDockerServerMatch(credentials[key].address, dockerCredential.address)) {
                console.log(tl.loc('ReplaceCredential', dockerCredential.address));
                credentials[key] = dockerCredential;
                break;
              }
            }
          }
        }
      }
  
      fs.writeFileSync(outputDeploymentJsonPath, JSON.stringify(deploymentJson, null, 2));
    }
  } catch (e) {
    tl.execSync(`docker`, `logout`, Constants.execSyncSilentOption);
    throw e;
  }
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:95,代码来源:pushimage.ts

示例7: setConsoleCodePage

export function setConsoleCodePage() {
    if (tl.osType() === "Windows_NT") {
        tl.execSync(path.resolve(process.env.windir, "system32", "chcp.com"), ["65001"]);
    }
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:5,代码来源:Utility.ts

示例8: runBuild

export async function runBuild(): Promise<void> {
  
  const aipPath: string = taskLib.getPathInput('AipPath', true, false);
  let aipBuild: string = taskLib.getInput('AipBuild');
  let aipPackageName: string = taskLib.getInput('AipPackageName');
  let aipOutputFolder: string = taskLib.getInput('AipOutputFolder');

  if (aipOutputFolder == taskLib.getVariable('BUILD_SOURCESDIRECTORY')) {
    taskLib.debug("Reset AipOutputFolder. OLD: $aipOutputFolder NEW:(empty).");
    aipOutputFolder = ""
  }

  const aipExtraCommands: string[] = taskLib.getDelimitedInput('AipExtraCommands', '\r\n');
  const aipResetDigSign: boolean = taskLib.getBoolInput('AipResetDigSign');

  // Log input parameters
  if (aipBuild == null) {
    aipBuild = '';
  }
  taskLib.debug(taskLib.loc("AI_StartTaskLog"));
  taskLib.debug("aipPath = " + aipPath);
  taskLib.debug("aipBuild  = " + aipBuild);
  taskLib.debug("aipPackageName = " + aipPackageName);
  taskLib.debug("aipOutputFolder = " + aipOutputFolder);
  taskLib.debug("aipExtraCommands = " + aipExtraCommands);
  taskLib.debug("aipResetDigSign = " + aipResetDigSign);

  // Validate "aipPath" input parameter.
  taskLib.checkPath(aipPath, aipPath);

  // Validate advinst tool path
  const advinstToolPath: string = await getAdvinstComTool();
  if (null == advinstToolPath) {
    throw new Error(taskLib.loc("AI_AdvinstNotFoundErr"));
  }

  // Compute the advinst commands
  let advinstCommands: string[] = [];
  if (aipPackageName) {
    advinstCommands.push(`SetPackageName \"${aipPackageName}\" -buildname \"${aipBuild}\"`);
  }

  if (aipOutputFolder) {
    advinstCommands.push(`SetOutputLocation -path \"${aipOutputFolder}\" -buildname \"${aipBuild}\"`);
  }

  if (aipResetDigSign) {
    advinstCommands.push('ResetSig');
  }

  if (aipExtraCommands.length > 0) {
    advinstCommands = advinstCommands.concat(aipExtraCommands);
  }

  advinstCommands.push(aipBuild ? `Build -buildslist \"${aipBuild}\"` : `Build`);

  //Execute the commands
  try {
    var commandsFilePath = getCommandsFile(advinstCommands);
    const advinstCmdLineArgs: string[] = ['/execute', `${aipPath}`, `${commandsFilePath}`];
    let result = taskLib.execSync(advinstToolPath, advinstCmdLineArgs);
    if (result.code != 0) {
      throw new Error(taskLib.loc("AI_ExecFailedErr", result.stdout));
    }
  }
  finally {
    if (commandsFilePath) {
      taskLib.rmRF(commandsFilePath);
    }
  }
}
开发者ID:Caphyon,项目名称:advinst-vsts-task,代码行数:71,代码来源:AdvinstBuilder.ts


注:本文中的azure-pipelines-task-lib/task.execSync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。