本文整理匯總了TypeScript中vsts-task-lib/task.osType函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript osType函數的具體用法?TypeScript osType怎麽用?TypeScript osType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了osType函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: downloadAndInstall
private async downloadAndInstall(downloadUrls: string[]) {
let downloaded = false;
let downloadPath = "";
for (const url of downloadUrls) {
try {
downloadPath = await toolLib.downloadTool(url);
downloaded = true;
break;
} catch (error) {
tl.warning(tl.loc("CouldNotDownload", url, JSON.stringify(error)));
}
}
if (!downloaded) {
throw tl.loc("FailedToDownloadPackage");
}
// extract
console.log(tl.loc("ExtractingPackage", downloadPath));
let extPath: string = tl.osType().match(/^Win/) ? await toolLib.extractZip(downloadPath) : await toolLib.extractTar(downloadPath);
// cache tool
console.log(tl.loc("CachingTool"));
let cachedDir = await toolLib.cacheDir(extPath, this.cachedToolName, this.version);
console.log(tl.loc("SuccessfullyInstalled", this.packageType, this.version));
return cachedDir;
}
示例2: getDefaultProps
function getDefaultProps() {
return {
releaseuri: tl.getVariable('Release.ReleaseUri'),
releaseid: tl.getVariable('Release.ReleaseId'),
builduri: tl.getVariable('Build.BuildUri'),
buildid: tl.getVariable('Build.Buildid'),
osType: tl.osType()
};
}
示例3: shouldUseVstsNuGetPush
function shouldUseVstsNuGetPush(isInternalFeed: boolean, conflictsAllowed: boolean, nugetExePath: string): boolean {
if (tl.osType() !== "Windows_NT"){
tl.debug("Running on a non-windows platform so NuGet.exe will be used.");
if(conflictsAllowed){
tl.warning(tl.loc("Warning_SkipConflictsNotSupportedUnixAgents"));
}
return false;
}
if (!isInternalFeed)
{
tl.debug("Pushing to an external feed so NuGet.exe will be used.");
return false;
}
if (commandHelper.isOnPremisesTfs())
{
tl.debug("Pushing to an onPrem environment, only NuGet.exe is supported.");
if(conflictsAllowed){
tl.warning(tl.loc("Warning_AllowDuplicatesOnlyAvailableHosted"));
}
return false;
}
const nugetOverrideFlag = tl.getVariable("NuGet.ForceNuGetForPush");
if (nugetOverrideFlag === "true") {
tl.debug("NuGet.exe is force enabled for publish.");
if(conflictsAllowed)
{
tl.warning(tl.loc("Warning_ForceNuGetCannotSkipConflicts"));
}
return false;
}
if (nugetOverrideFlag === "false") {
tl.debug("NuGet.exe is force disabled for publish.");
return true;
}
const vstsNuGetPushOverrideFlag = tl.getVariable("NuGet.ForceVstsNuGetPushForPush");
if (vstsNuGetPushOverrideFlag === "true") {
tl.debug("VstsNuGetPush.exe is force enabled for publish.");
return true;
}
if (vstsNuGetPushOverrideFlag === "false") {
tl.debug("VstsNuGetPush.exe is force disabled for publish.");
if(conflictsAllowed)
{
tl.warning(tl.loc("Warning_ForceNuGetCannotSkipConflicts"));
}
return false;
}
return true;
}
示例4: getOctoCommandRunner
export function getOctoCommandRunner(command: string) : Option<ToolRunner> {
const isWindows = /windows/i.test(tasks.osType());
if(isWindows){
return stringOption(tasks.which(`${ToolName}`, false))
.map(tasks.tool)
.map(x => x.arg(command));
}
return getPortableOctoCommandRunner(command);
}
示例5: downloadAndInstall
public async downloadAndInstall(versionInfo: VersionInfo, downloadUrl: string): Promise<void> {
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));
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)) {
tl.debug(tl.loc("CopyingFilesIntoPath", this.installationPath));
var filesToBeCopied = allRootLevelEnteriesInDir.filter(path => !fs.lstatSync(path).isDirectory());
filesToBeCopied.forEach((filePath) => {
tl.cp(filePath, this.installationPath, "-f", false);
});
}
}
catch (ex) {
tl.warning(tl.loc("FailedToCopyTopLevelFiles", this.installationPath, ex));
}
// Cache tool
this.createInstallationCompleteFile(versionInfo);
console.log(tl.loc("SuccessfullyInstalled", this.packageType, version));
}
catch (ex) {
throw tl.loc("FailedWhileInstallingVersionAtPath", version, this.installationPath, ex);
}
}
示例6: detectMachineOS
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;
}
示例7: addDotNetCoreToolPath
function addDotNetCoreToolPath() {
try {
let globalToolPath: string = "";
if (tl.osType().match(/^Win/)) {
globalToolPath = path.join(process.env.USERPROFILE, Constants.relativeGlobalToolPath);
} else {
globalToolPath = path.join(process.env.HOME, Constants.relativeGlobalToolPath);
}
console.log(tl.loc("PrependGlobalToolPath"));
tl.mkdirP(globalToolPath);
toolLib.prependPath(globalToolPath);
} catch (error) {
//nop
console.log(tl.loc("ErrorWhileSettingDotNetToolPath", JSON.stringify(error)));
}
}
示例8: detectMachineOS
private detectMachineOS(): string[] {
let osSuffix = [];
if (tl.osType().match(/^Win/)) {
let primary = "win-" + os.arch();
osSuffix.push(primary);
console.log(tl.loc("PrimaryPlatform", primary));
}
else {
let scriptPath = path.join(utilities.getCurrentDir(), 'externals', 'get-os-distro.sh');
utilities.setFileAttribute(scriptPath, "777");
let scriptRunner: trm.ToolRunner = 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");
}
}
return osSuffix;
}
示例9: acquireDotNetCore
async function acquireDotNetCore(packageType: string, version: string): Promise<string> {
let downloadUrls = getDownloadUrls(packageType, version);
let downloadPath: string;
try {
// try primary url
if (!!downloadUrls[0]) {
console.log(taskLib.loc("DownloadingPrimaryUrl", downloadUrls[0]));
downloadPath = await toolLib.downloadTool(downloadUrls[0]);
}
} catch (error1) {
console.log(taskLib.loc("PrimaryUrlDownloadFailed", error1));
try {
// try secondary url
if (!!downloadUrls[1]) {
console.log(taskLib.loc("DownloadingSecondaryUrl", downloadUrls[1]));
downloadPath = await toolLib.downloadTool(downloadUrls[1]);
}
} catch (error2) {
console.log(taskLib.loc("LegacyUrlDownloadFailed", error2));
throw taskLib.loc("DownloadFailed", packageType, version);
}
}
// extract
let extPath: string;
console.log(taskLib.loc("ExtractingPackage", downloadPath));
if (taskLib.osType().match(/^Win/)) {
extPath = await toolLib.extractZip(downloadPath);
}
else {
extPath = await toolLib.extractTar(downloadPath);
}
// cache tool
let cachedToolName = getCachedToolName(packageType);
console.log(taskLib.loc("CachingTool"));
let cachedDir = await toolLib.cacheDir(extPath, cachedToolName, version);
console.log(taskLib.loc("SuccessfullyInstalled", packageType, version));
return cachedDir;
}
示例10: install
public async install() {
// Check cache
let toolPath: string;
let osSuffixes = this.detectMachineOS();
let parts = osSuffixes[0].split("-");
this.arch = parts.length > 1 ? parts[1] : "x64";
toolPath = this.getLocalTool();
if (!toolPath) {
// download, extract, cache
console.log(tl.loc("InstallingAfresh"));
console.log(tl.loc("GettingDownloadUrl", this.packageType, this.version));
let downloadUrls = await DotNetCoreReleaseFetcher.getDownloadUrls(osSuffixes, this.version, this.packageType);
toolPath = await this.downloadAndInstall(downloadUrls);
} else {
console.log(tl.loc("UsingCachedTool", toolPath));
}
// Prepend the tools path. instructs the agent to prepend for future tasks
toolLib.prependPath(toolPath);
try {
let globalToolPath: string = "";
if (tl.osType().match(/^Win/)) {
globalToolPath = path.join(process.env.USERPROFILE, ".dotnet\\tools");
} else {
globalToolPath = path.join(process.env.HOME, ".dotnet/tools");
}
console.log(tl.loc("PrependGlobalToolPath"));
tl.mkdirP(globalToolPath);
toolLib.prependPath(globalToolPath);
} catch (error) {
//nop
}
// Set DOTNET_ROOT for dotnet core Apphost to find runtime since it is installed to a non well-known location.
tl.setVariable('DOTNET_ROOT', toolPath);
}