Skip to content

Commit 54388b5

Browse files
authoredFeb 24, 2022
use compliant build environment for release build. (#1776)
* use compliant build environment for release build. * Fix for underlying changes in build environments to find the proper dotnet.exe * build debug -w 01 * build debug -w 02 * build debug -w 03 * build debug -w 04
1 parent 416a4b1 commit 54388b5

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed
 

‎.ci/releaseBuild.yml

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ stages:
3535
displayName: Build
3636
pool:
3737
name: PowerShell1ES # was Package ES CodeHub Lab E
38+
demands:
39+
- ImageOverride -equals PSMMS2019-Secure
3840
jobs:
3941
- job: Build_Job
4042
displayName: Build Microsoft.PowerShell.ScriptAnalyzer

‎build.psm1

+27-13
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function Start-ScriptAnalyzerBuild
161161
# install the proper version
162162
Install-Dotnet
163163
if ( -not (Test-SuitableDotnet) ) {
164-
$requiredVersion = Get-GlobalJsonSdkVersion
164+
$requiredVersion = $script:wantedVersion
165165
$foundVersion = Get-InstalledCLIVersion
166166
Write-Warning "No suitable dotnet CLI found, requires version '$requiredVersion' found only '$foundVersion'"
167167
}
@@ -184,6 +184,7 @@ function Start-ScriptAnalyzerBuild
184184
{
185185
# Build all the versions of the analyzer
186186
foreach ($psVersion in 3, 4, 5, 7) {
187+
Write-Verbose -Verbose -Message "Configuration: $Configuration PSVersion: $psVersion"
187188
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion -Verbose:$verboseWanted
188189
}
189190
if ( $Catalog ) {
@@ -271,12 +272,17 @@ function Start-ScriptAnalyzerBuild
271272
$dotnetArgs += "${PSScriptRoot}\bin\${buildConfiguration}\${framework}"
272273
}
273274
$buildOutput = & $script:DotnetExe $dotnetArgs 2>&1
274-
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
275+
if ( $LASTEXITCODE -ne 0 ) {
276+
Write-Verbose -Verbose -Message "dotnet is $(${script:DotnetExe}.Source)"
277+
$dotnetArgs | Foreach-Object {"dotnetArg: $_"} | Write-Verbose -Verbose
278+
Get-PSCallStack | Write-Verbose -Verbose
279+
throw $buildOutput
280+
}
275281
Write-Verbose -Verbose:$verboseWanted -message "$buildOutput"
276282
}
277283
catch {
278-
Write-Warning $_
279-
Write-Error "Failure to build for PSVersion '$PSVersion' using framework '$framework' and configuration '$config'"
284+
$_.TargetObject | Write-Warning
285+
Write-Error "Failure to build for PSVersion '$PSVersion' using framework '$framework' and configuration '$buildConfiguration'"
280286
throw
281287
}
282288
finally {
@@ -545,7 +551,7 @@ function ConvertTo-PortableVersion {
545551
function Test-SuitableDotnet {
546552
param (
547553
$availableVersions = $( Get-InstalledCliVersion),
548-
$requiredVersion = $( Get-GlobalJsonSdkVersion )
554+
$requiredVersion = $script:wantedVersion
549555
)
550556

551557
if ( $requiredVersion -is [String] -or $requiredVersion -is [Version] ) {
@@ -610,7 +616,7 @@ function Get-InstalledCLIVersion {
610616
function Test-DotnetInstallation
611617
{
612618
param (
613-
$requestedVersion = $( Get-GlobalJsonSdkVersion ),
619+
$requestedVersion = $script:wantedVersion,
614620
$installedVersions = $( Get-InstalledCLIVersion )
615621
)
616622
return (Test-SuitableDotnet -availableVersions $installedVersions -requiredVersion $requestedVersion )
@@ -671,7 +677,8 @@ function Receive-DotnetInstallScript
671677

672678
function Get-DotnetExe
673679
{
674-
$discoveredDotnet = Get-Command -CommandType Application dotnet -ErrorAction SilentlyContinu
680+
param ( $version = $script:wantedVersion )
681+
$discoveredDotnet = Get-Command -CommandType Application dotnet -ErrorAction SilentlyContinue -All
675682
if ( $discoveredDotnet ) {
676683
# it's possible that there are multiples. Take the highest version we find
677684
# the problem is that invoking dotnet on a version which is lower than the specified
@@ -682,13 +689,17 @@ function Get-DotnetExe
682689
# file points to a version of the sdk which is *not* installed. However, the format of the new list
683690
# with --version has a couple of spaces at the beginning of the line, so we need to be resilient
684691
# against that.
685-
$latestDotnet = $discoveredDotNet |
686-
Where-Object { try { & $_ --version 2>$null } catch { } } |
687-
Sort-Object { $pv = ConvertTo-PortableVersion (& $_ --version 2>$null| %{$_.Trim().Split()[0]}); "$pv" } |
692+
$properDotnet = $discoveredDotNet |
693+
Where-Object {
694+
& $_ --list-sdks |
695+
Where-Object {
696+
$_ -match $version
697+
}
698+
} |
688699
Select-Object -Last 1
689-
if ( $latestDotnet ) {
690-
$script:DotnetExe = $latestDotnet
691-
return $latestDotnet
700+
if ( $properDotnet ) {
701+
$script:DotnetExe = $properDotnet
702+
return $properDotnet
692703
}
693704
}
694705
# it's not in the path, try harder to find it by checking some usual places
@@ -714,6 +725,9 @@ function Get-DotnetExe
714725
}
715726

716727
try {
728+
# The version we want based on the global.JSON file
729+
# suck this before getting the dotnet exe
730+
$script:wantedVersion = Get-GlobalJsonSdkVersion -Raw
717731
$script:DotnetExe = Get-DotnetExe
718732
}
719733
catch {

0 commit comments

Comments
 (0)
Please sign in to comment.