1+ [CmdletBinding (DefaultParameterSetName = ' RegularBuild' )]
2+ param (
3+ [ValidateSet (" debug" , " release" )]
4+ [string ]$Configuration = ' debug' ,
5+ [ValidateSet (" Release" , " rtm" , " rc" , " beta" , " beta2" , " final" , " xprivate" , " zlocal" )]
6+ [string ]$ReleaseLabel = ' zlocal' ,
7+ [int ]$BuildNumber ,
8+ [switch ]$SkipRestore ,
9+ [switch ]$CleanCache ,
10+ [string ]$SimpleVersion = ' 1.0.0' ,
11+ [string ]$SemanticVersion = ' 1.0.0-zlocal' ,
12+ [string ]$Branch ,
13+ [string ]$CommitSHA ,
14+ [string ]$BuildBranch = ' a8c27302d8720d094c2dce87e00324d84b4697b2'
15+ )
16+
17+ # For TeamCity - If any issue occurs, this script fails the build. - By default, TeamCity returns an exit code of 0 for all powershell scripts, even if they fail
18+ trap {
19+ Write-Host " BUILD FAILED: $_ " - ForegroundColor Red
20+ Write-Host " ERROR DETAILS:" - ForegroundColor Red
21+ Write-Host $_.Exception - ForegroundColor Red
22+ Write-Host (" `r`n " * 3 )
23+ exit 1
24+ }
25+
26+ if (-not (Test-Path " $PSScriptRoot /build" )) {
27+ New-Item - Path " $PSScriptRoot /build" - ItemType " directory"
28+ }
29+ wget - UseBasicParsing - Uri " https://raw.githubusercontent.com/NuGet/ServerCommon/$BuildBranch /build/init.ps1" - OutFile " $PSScriptRoot /build/init.ps1"
30+ . " $PSScriptRoot /build/init.ps1" - BuildBranch " $BuildBranch "
31+
32+ Function Clean-Tests {
33+ [CmdletBinding ()]
34+ param ()
35+
36+ Trace-Log ' Cleaning test results'
37+
38+ Remove-Item (Join-Path $PSScriptRoot " Results.*.xml" )
39+ }
40+
41+ Function Prepare-Vcs-Callback {
42+ [CmdletBinding ()]
43+ param ()
44+
45+ Trace-Log ' Preparing Validation.Callback.Vcs Package'
46+
47+ $ZipPackagePath = " src\Validation.Callback.Vcs\obj\Validation.Callback.Vcs.zip"
48+
49+ if (Test-Path $ZipPackagePath ) {
50+ Remove-Item $ZipPackagePath
51+ }
52+
53+ Build-Solution $Configuration $BuildNumber - MSBuildVersion " 14" " src\Validation.Callback.Vcs\Validation.Callback.Vcs.csproj" - Target " Package" - MSBuildProperties " /P:PackageLocation=obj\Validation.Callback.Vcs.zip" - SkipRestore
54+ }
55+
56+ Write-Host (" `r`n " * 3 )
57+ Trace-Log (' =' * 60 )
58+
59+ $startTime = [DateTime ]::UtcNow
60+ if (-not $BuildNumber ) {
61+ $BuildNumber = Get-BuildNumber
62+ }
63+ Trace-Log " Build #$BuildNumber started at $startTime "
64+
65+ $BuildErrors = @ ()
66+
67+ Invoke-BuildStep ' Cleaning test results' { Clean - Tests } `
68+ - ev + BuildErrors
69+
70+ Invoke-BuildStep ' Installing NuGet.exe' { Install-NuGet } `
71+ - ev + BuildErrors
72+
73+ Invoke-BuildStep ' Clearing package cache' { Clear-PackageCache } `
74+ - skip:(-not $CleanCache ) `
75+ - ev + BuildErrors
76+
77+ Invoke-BuildStep ' Clearing artifacts' { Clear-Artifacts } `
78+ - ev + BuildErrors
79+
80+ Invoke-BuildStep ' Restoring solution packages' { `
81+ Install-SolutionPackages - path (Join-Path $PSScriptRoot " .nuget\packages.config" ) - output (Join-Path $PSScriptRoot " packages" ) - ExcludeVersion } `
82+ - skip:$SkipRestore `
83+ - ev + BuildErrors
84+
85+ Invoke-BuildStep ' Building solution' {
86+ param ($Configuration , $BuildNumber , $SolutionPath , $SkipRestore )
87+ Build-Solution $Configuration $BuildNumber - MSBuildVersion " 14" $SolutionPath - SkipRestore:$SkipRestore `
88+ } `
89+ - args $Configuration , $BuildNumber , (Join-Path $PSScriptRoot " NuGet.Jobs.sln" ), $SkipRestore `
90+ - ev + BuildErrors
91+
92+ Invoke-BuildStep ' Prepare Validation.Callback.Vcs Package' { Prepare- Vcs- Callback } `
93+ - ev + BuildErrors
94+
95+ Invoke-BuildStep ' Creating artifacts' {
96+ $Projects = " src/Stats.CollectAzureCdnLogs/Stats.CollectAzureCdnLogs.csproj" , `
97+ " src/Stats.AggregateCdnDownloadsInGallery/Stats.AggregateCdnDownloadsInGallery.csproj" , `
98+ " src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj" , `
99+ " src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj" , `
100+ " src/UpdateLicenseReports/UpdateLicenseReports.csproj" , `
101+ " src/Gallery.CredentialExpiration/Gallery.CredentialExpiration.csproj" , `
102+ " src/ArchivePackages/ArchivePackages.csproj" , `
103+ " src/Search.GenerateAuxiliaryData/Search.GenerateAuxiliaryData.csproj" , `
104+ " src/HandlePackageEdits/HandlePackageEdits.csproj" , `
105+ " src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj" , `
106+ " src/Validation.Callback.Vcs/Validation.Callback.Vcs.csproj" , `
107+ " src/Validation.Runner/Validation.Runner.csproj"
108+
109+ Foreach ($Project in $Projects ) {
110+ New-Package (Join-Path $PSScriptRoot " $Project " ) - Configuration $Configuration - BuildNumber $BuildNumber - ReleaseLabel $ReleaseLabel - Version $SemanticVersion - Branch $Branch
111+ }
112+ } `
113+ - ev + BuildErrors
114+
115+ Trace-Log (' -' * 60 )
116+
117+ # # Calculating Build time
118+ $endTime = [DateTime ]::UtcNow
119+ Trace-Log " Build #$BuildNumber ended at $endTime "
120+ Trace-Log " Time elapsed $ ( Format-ElapsedTime ($endTime - $startTime )) "
121+
122+ Trace-Log (' =' * 60 )
123+
124+ if ($BuildErrors ) {
125+ $ErrorLines = $BuildErrors | % { " >>> $ ( $_.Exception.Message ) " }
126+ Error- Log " Builds completed with $ ( $BuildErrors.Count ) error(s):`r`n $ ( $ErrorLines -join " `r`n " ) " - Fatal
127+ }
128+
129+ Write-Host (" `r`n " * 3 )
0 commit comments