本文整理匯總了TypeScript中vsts-task-lib/task.execSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript execSync函數的具體用法?TypeScript execSync怎麽用?TypeScript execSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了execSync函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
}
}
示例2: addBaseEnvironmentToPath
export function addBaseEnvironmentToPath(platform: Platform): void {
const execResult = task.execSync('conda', 'info --base');
if (execResult.error) {
throw execResult.error;
}
const baseEnv = execResult.stdout.trim();
prependPathSafe(binaryDir(baseEnv, platform));
}
示例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} )`);
}
}
示例4: main
async function main(): Promise<void> {
let buildIdentityDisplayName: string = null;
let buildIdentityAccount: string = null;
try {
tl.setResourcePath(path.join(__dirname, "task.json"));
// set the console code page to "UTF-8"
if (process.platform === "win32") {
tl.execSync(path.resolve(process.env.windir, "system32", "chcp.com"), ["65001"]);
}
// read inputs
let searchPattern = tl.getPathInput("searchPattern", true, false);
let filesList = nutil.resolveFilterSpec(
searchPattern,
tl.getVariable("System.DefaultWorkingDirectory") || process.cwd());
filesList.forEach(packageFile => {
if (!tl.stats(packageFile).isFile()) {
throw new Error(tl.loc("NotARegularFile", packageFile));
}
});
let connectedServiceName = tl.getInput("connectedServiceName");
let internalFeedUri = tl.getInput("feedName");
let nuGetAdditionalArgs = tl.getInput("nuGetAdditionalArgs");
let verbosity = tl.getInput("verbosity");
let nuGetFeedType = tl.getInput("nuGetFeedType") || "external";
// make sure the feed type is an expected one
let normalizedNuGetFeedType
= ["internal", "external"].find(x => nuGetFeedType.toUpperCase() === x.toUpperCase());
if (!normalizedNuGetFeedType) {
throw new Error(tl.loc("UnknownFeedType", nuGetFeedType));
}
nuGetFeedType = normalizedNuGetFeedType;
// due to a bug where we accidentally allowed nuGetPath to be surrounded by quotes before,
// locateNuGetExe() will strip them and check for existence there.
let nuGetPath = tl.getPathInput("nuGetPath", false, false);
let nugetVersion = tl.getInput("nuGetversion");
let userNuGetProvided = false;
if (tl.filePathSupplied("nuGetPath")) {
nuGetPath = nutil.stripLeadingAndTrailingQuotes(nuGetPath);
userNuGetProvided = true;
if (nugetVersion !== "custom")
{
// For back compat, if a path has already been specified then use it.
// However, warn the user in the build of this behavior.
tl.warning(tl.loc("Warning_ConflictingNuGetPreference"));
}
}
else {
if (nugetVersion === "custom")
{
throw new Error(tl.loc("NoNuGetSpecified"))
}
nuGetPath = nutil.getBundledNuGetLocation(nugetVersion);
}
let serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
//find nuget location to use
let credProviderPath = ngToolRunner.locateCredentialProvider();
const quirks = await ngToolRunner.getNuGetQuirksAsync(nuGetPath);
// clauses ordered in this way to avoid short-circuit evaluation, so the debug info printed by the functions
// is unconditionally displayed
const useCredProvider = ngToolRunner.isCredentialProviderEnabled(quirks) && credProviderPath;
const useCredConfig = ngToolRunner.isCredentialConfigEnabled(quirks) && !useCredProvider;
let accessToken = auth.getSystemAccessToken();
let urlPrefixes = await locationHelpers.assumeNuGetUriPrefixes(serviceUri);
tl.debug(`discovered URL prefixes: ${urlPrefixes}`);
// Note to readers: This variable will be going away once we have a fix for the location service for
// customers behind proxies
let testPrefixes = tl.getVariable("NuGetTasks.ExtraUrlPrefixesForTesting");
if (testPrefixes) {
urlPrefixes = urlPrefixes.concat(testPrefixes.split(";"));
tl.debug(`all URL prefixes: ${urlPrefixes}`);
}
const authInfo = new auth.NuGetAuthInfo(urlPrefixes, accessToken);
let environmentSettings: ngToolRunner.NuGetEnvironmentSettings = {
authInfo: authInfo,
credProviderFolder: useCredProvider ? path.dirname(credProviderPath) : null,
extensionsDisabled: !userNuGetProvided
}
let configFile = null;
let apiKey: string;
let feedUri: string;
let credCleanup = () => { return };
if (nuGetFeedType == "internal") {
if (useCredConfig) {
let nuGetConfigHelper = new NuGetConfigHelper(nuGetPath, null, authInfo, environmentSettings);
nuGetConfigHelper.setSources([{ feedName: "internalFeed", feedUri: internalFeedUri }]);
configFile = nuGetConfigHelper.tempNugetConfigPath;
//.........這裏部分代碼省略.........
示例5: setConsoleCodePage
export function setConsoleCodePage() {
if (tl.osType() === "Windows_NT") {
tl.execSync(path.resolve(process.env.windir, "system32", "chcp.com"), ["65001"]);
}
}
示例6: main
async function main(): Promise<void> {
let buildIdentityDisplayName: string = null;
let buildIdentityAccount: string = null;
try {
tl.setResourcePath(path.join(__dirname, "task.json"));
// set the console code page to "UTF-8"
if (process.platform === "win32") {
tl.execSync(path.resolve(process.env.windir, "system32", "chcp.com"), ["65001"]);
}
// read inputs
let solution = tl.getPathInput("solution", true, false);
let filesList = nutil.resolveFilterSpec(
solution,
tl.getVariable("System.DefaultWorkingDirectory") || process.cwd());
filesList.forEach(solutionFile => {
if (!tl.stats(solutionFile).isFile()) {
throw new Error(tl.loc("NotARegularFile", solutionFile));
}
});
let noCache = tl.getBoolInput("noCache");
let nuGetRestoreArgs = tl.getInput("nuGetRestoreArgs");
let verbosity = tl.getInput("verbosity");
let restoreMode = tl.getInput("restoreMode") || "Restore";
// normalize the restore mode for display purposes, and ensure it's a known one
let normalizedRestoreMode = ["restore", "install"].find(x => restoreMode.toUpperCase() === x.toUpperCase());
if (!normalizedRestoreMode) {
throw new Error(tl.loc("UnknownRestoreMode", restoreMode));
}
restoreMode = normalizedRestoreMode;
let nugetConfigPath = tl.getPathInput("nugetConfigPath", false, true);
if (!tl.filePathSupplied("nugetConfigPath")) {
nugetConfigPath = null;
}
// due to a bug where we accidentally allowed nuGetPath to be surrounded by quotes before,
// locateNuGetExe() will strip them and check for existence there.
let userNuGetPath = tl.getPathInput("nuGetPath", false, false);
if (!tl.filePathSupplied("nuGetPath")) {
userNuGetPath = null;
}
let serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
// find nuget location to use
let nuGetPathToUse = ngToolRunner.locateNuGetExe(userNuGetPath);
let credProviderPath = ngToolRunner.locateCredentialProvider();
const quirks = await ngToolRunner.getNuGetQuirksAsync(nuGetPathToUse);
// clauses ordered in this way to avoid short-circuit evaluation, so the debug info printed by the functions
// is unconditionally displayed
const useCredProvider = ngToolRunner.isCredentialProviderEnabled(quirks) && credProviderPath;
const useCredConfig = ngToolRunner.isCredentialConfigEnabled(quirks) && !useCredProvider;
let accessToken = auth.getSystemAccessToken();
let urlPrefixes = await locationHelpers.assumeNuGetUriPrefixes(serviceUri);
tl.debug(`discovered URL prefixes: ${urlPrefixes}`);
// Note to readers: This variable will be going away once we have a fix for the location service for
// customers behind proxies
let testPrefixes = tl.getVariable("NuGetTasks.ExtraUrlPrefixesForTesting");
if (testPrefixes) {
urlPrefixes = urlPrefixes.concat(testPrefixes.split(";"));
tl.debug(`all URL prefixes: ${urlPrefixes}`);
}
const authInfo = new auth.NuGetAuthInfo(urlPrefixes, accessToken);
let environmentSettings: ngToolRunner.NuGetEnvironmentSettings = {
authInfo: authInfo,
credProviderFolder: useCredProvider ? path.dirname(credProviderPath) : null,
extensionsDisabled: !userNuGetPath,
};
let configFile = nugetConfigPath;
let credCleanup = () => { return; };
if (useCredConfig) {
if (nugetConfigPath) {
let nuGetConfigHelper = new NuGetConfigHelper(
nuGetPathToUse,
nugetConfigPath,
authInfo,
environmentSettings);
const packageSources = await nuGetConfigHelper.getSourcesFromConfig();
if (packageSources.length !== 0) {
nuGetConfigHelper.setSources(packageSources);
credCleanup = () => tl.rmRF(nuGetConfigHelper.tempNugetConfigPath, true);
configFile = nuGetConfigHelper.tempNugetConfigPath;
}
}
else {
if (credProviderPath) {
tl.warning(tl.loc("Warning_NoConfigForOldNuGet"));
//.........這裏部分代碼省略.........