Files
runner-images-sangeeth/images/linux/scripts/helpers/Common.Helpers.psm1
Aleksandr Chebotov 92eeb55189 [Ubuntu] Add verbosity during software report generation (#4811)
* Add verbosity during software report generation

* Fix Get-CpanVersion

* set default ValidateExitCode value to $true

* update java test

* use lower-case for parameters
2021-12-28 11:16:20 +03:00

78 lines
2.0 KiB
PowerShell

function Get-CommandResult {
param (
[Parameter(Mandatory=$true)]
[string] $Command,
[int[]] $ExpectExitCode = 0,
[switch] $Multiline,
[bool] $ValidateExitCode = $true
)
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
$stdout = & bash -c "$Command 2>&1"
$exitCode = $LASTEXITCODE
if ($ValidateExitCode) {
if ($ExpectExitCode -notcontains $exitCode) {
try {
throw "StdOut: '$stdout' ExitCode: '$exitCode'"
} catch {
Write-Host $_.Exception.Message
Write-Host $_.ScriptStackTrace
exit $LASTEXITCODE
}
}
}
return @{
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
ExitCode = $exitCode
}
}
function Get-OSName {
lsb_release -ds
}
function Get-KernelVersion {
$kernelVersion = uname -r
return "Linux kernel version: $kernelVersion"
}
function Test-IsUbuntu18 {
return (lsb_release -rs) -eq "18.04"
}
function Test-IsUbuntu20 {
return (lsb_release -rs) -eq "20.04"
}
function Get-ToolsetContent {
$toolset = Join-Path $env:INSTALLER_SCRIPT_FOLDER "toolset.json"
Get-Content $toolset -Raw | ConvertFrom-Json
}
function Get-ToolsetValue {
param (
[Parameter(Mandatory = $true)]
[string] $KeyPath
)
$jsonNode = Get-ToolsetContent
$pathParts = $KeyPath.Split(".")
# try to walk through all arguments consequentially to resolve specific json node
$pathParts | ForEach-Object {
$jsonNode = $jsonNode.$_
}
return $jsonNode
}
function Get-AndroidPackages {
$androidSDKManagerPath = "/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager"
$androidPackages = & $androidSDKManagerPath --list --verbose
return $androidPackages
}
function Get-EnvironmentVariable($variable) {
return [System.Environment]::GetEnvironmentVariable($variable)
}