Last active
June 21, 2022 20:24
-
-
Save lennybacon/0d9b6d29eafd44b88bd171803a9535f1 to your computer and use it in GitHub Desktop.
Totally automated Team Foundation 2017 build agent setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tfsUrl = "https://domain.tld/"; | |
$tfsCollection = "DefaultCollection"; | |
$tfsProject = "projectName"; | |
$nugetSourceName = "Libraries"; | |
$nugetFeedUrl = "$tfsUrl/$tfsCollection/_packaging/Libraries/nuget/v3/index.json"; | |
$nugetUserName = "TfsBuild"; | |
$nugetPassword = "*******"; | |
$ErrorActionPreference="Stop"; | |
If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( | |
[Security.Principal.WindowsBuiltInRole] "Administrator")){ | |
throw "Run command in Administrator PowerShell Prompt" | |
}; | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v2.0.50727 -Name SystemDefaultTlsVersions -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v2.0.50727 -Name SchUseStrongCrypto -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319 -Name SystemDefaultTlsVersions -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319 -Name SchUseStrongCrypto -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\Microsoft\.NETFramework\v2.0.50727 -Name SystemDefaultTlsVersions -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\Microsoft\.NETFramework\v2.0.50727 -Name SchUseStrongCrypto -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 -Name SystemDefaultTlsVersions -Value 1 -Type DWord | |
Set-ItemProperty -Path HKLM:\\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 -Name SchUseStrongCrypto -Value 1 -Type DWord | |
If(-NOT (Test-Path $env:SystemDrive\'vstsagent')){ | |
mkdir $env:SystemDrive\'vstsagent' | |
} | |
cd $env:SystemDrive\'vstsagent'; | |
$agentZip="$PWD\agent.zip"; | |
(New-Object Net.WebClient).DownloadFile( | |
"https://go.microsoft.com/fwlink/?linkid=858950", $agentZip); | |
Add-Type -AssemblyName System.IO.Compression.FileSystem; | |
[System.IO.Compression.ZipFile]::ExtractToDirectory($agentZip, "$PWD"); | |
Remove-Item $agentZip; | |
.\config.cmd ` | |
--agent $env:COMPUTERNAME ` | |
--runasservice ` | |
--work "_work" ` | |
--url "$tfsUrl" ` | |
--collectionname "$tfsCollection" ` | |
--projectname "$tfsProject"; | |
choco install nuget.commandline -y | |
choco install rsat -y | |
choco install lockhunter -y | |
choco install visualstudio2017community -y | |
# https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio | |
# https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community | |
Start-Process ` | |
-FilePath "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" ` | |
-Wait ` | |
-ArgumentList @( ` | |
"update", | |
"--installPath `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community`"", | |
"--norestart", | |
"--quiet" | |
) | |
Start-Process ` | |
-FilePath "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" ` | |
-Wait ` | |
-ArgumentList @( ` | |
"modify", | |
"--installPath `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community`"", | |
"--add Microsoft.VisualStudio.Component.VC.CoreIde", | |
"--add Microsoft.VisualStudio.Component.Windows10SDK", | |
"--add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop", | |
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64", | |
"--add Microsoft.VisualStudio.Component.TextTemplating", | |
"--add Microsoft.Component.NetFX.Core.Runtime", | |
"--add Microsoft.Net.Core.Component.SDK", | |
"--add Microsoft.NetCore.ComponentGroup.DevelopmentTools", | |
"--add Microsoft.VisualStudio.ComponentGroup.Web", | |
"--add Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions", | |
"--add Microsoft.VisualStudio.Component.Web", | |
"--add Microsoft.VisualStudio.Component.AspNet45", | |
"--add Microsoft.Net.Component.4.TargetingPack", | |
"--add Microsoft.Net.Component.4.5.1.TargetingPack", | |
"--add Microsoft.Net.Component.4.5.2.TargetingPack", | |
"--add Microsoft.Net.Component.4.6.TargetingPack", | |
"--add Microsoft.Net.Component.4.6.1.TargetingPack", | |
"--add Microsoft.Net.Component.4.6.1.SDK", | |
"--add Microsoft.Net.Component.4.6.2.TargetingPack", | |
"--add Microsoft.Net.Component.4.6.2.SDK", | |
"--add Microsoft.Net.Component.4.7.TargetingPack", | |
"--add Microsoft.Net.Component.4.7.SDK", | |
"--norestart", | |
"--quiet" | |
) | |
choco install wixtoolset -y | |
$extensionDisplayName = "Wix Toolset Visual Studio 2017 Extension"; | |
$extensionApiVersion = "api-version=3.2-preview.1" | |
$marketplaceQueryUrl = "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery"; | |
$extensionQuery = "{`"flags`":`"262`",`"filters`":[{`"criteria`":[{`"filterType`":`"14`",`"value`":`"1033`"},{`"filterType`":`"8`",`"value`":`"Microsoft.VisualStudio.Community`"},{`"filterType`":`"10`",`"value`":`"$extensionDisplayName`"}],`"sortBy`":`"0`",`"sortOrder`":`"2`",`"pageSize`":`"1`",`"pageNumber`":`"1`"}]}" | |
$webClient = New-Object System.Net.WebClient | |
$webClient.Headers["Accept"] = "application/json; $extensionApiVersion"; | |
$webClient.Headers["Content-Type"] = "application/json; charset=utf-8"; | |
$extensionQueryResponse = $webClient.UploadString($marketplaceQueryUrl, $extensionQuery); | |
$extensionQueryResponsJson = $extensionQueryResponse | ConvertFrom-Json | |
$extensionUrl = $extensionQueryResponsJson.results[0].extensions[0].versions[0].files | Where-Object { $_.assetType.EndsWith(".vsix")} | Select-Object -ExpandProperty source -First 1; | |
$extensionFileName = [IO.Path]::GetFileName($extensionUrl) | |
$extensionFilePath = ".\$extensionFileName" | |
if(Test-Path $extensionFilePath){ | |
Remove-Item $extensionFilePath -Force | |
} | |
(New-Object System.Net.WebClient).DownloadFile($extensionUrl, $extensionFilePath) | |
$vsixInstaller = Get-ChildItem -Path "$(${env:ProgramFiles(x86)})\Microsoft Visual Studio" | | |
? { !$PsIsContainer -and $_.Name.StartsWith("20") } | | |
% { @([System.IO.Path]::Combine($_.FullName, "Enterprise", "Common7\IDE"), [System.IO.Path]::Combine($_.FullName, "Professional", "Common7\IDE"), [System.IO.Path]::Combine($_.FullName, "Community", "Common7\IDE"))} | | |
? { (Test-Path -Path $_) } | | |
% { Get-ChildItem -Path $_ | ? { !$PsIsContainer -and $_.Name.Equals("VSIXInstaller.exe", "OrdinalIgnoreCase") } } | | |
Select-Object -ExpandProperty FullName -First 1 | |
$installProcess = Start-Process ` | |
-FilePath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VSIXInstaller.exe" ` | |
-Wait ` | |
-ArgumentList @( | |
"/q", | |
"/skuName:Community", | |
"/skuVersion:15.0" | |
"$extensionFilePath" | |
) | |
if(Test-Path $extensionFilePath){ | |
Remove-Item $extensionFilePath -Force | |
} | |
choco install visualstudiocode -y | |
choco install gitversion.portable --pre -y | |
choco install nodejs -y | |
choco install python2 -y | |
$path = ([System.Environment]::GetEnvironmentVariable("PATH").Replace("C:\Python27", "") + ";C:\Python27").Replace(";;", ";"); | |
[System.Environment]::SetEnvironmentVariable("PATH", $path); | |
& SETX PATH "$path" /M | |
refreshenv | |
npm install node-gyp --global | |
npm config set msvs_version 2017 | |
npm i node-sass -g | |
npm rebuild node-sass --force | |
npm i gulp -g | |
nuget.exe sources Add -Name "$nugetSourceName" -Source "$nugetFeedUrl" -UserName $nugetUserName -Password $nugetPassword | |
Add-MpPreference -ExclusionProcess "light.exe" | |
Add-MpPreference -ExclusionProcess "candel.exe" | |
Add-MpPreference -ExclusionProcess "msbuild.exe" | |
Add-MpPreference -ExclusionProcess "VBCSCompiler.exe" | |
Add-MpPreference -ExclusionPath "T:\Temp" | |
Add-MpPreference -ExclusionPath "C:\Program Files (x86)\Microsoft Visual Studio\" | |
Add-MpPreference -ExclusionPath "C:\Users\TfsBuild\.nuget\" | |
Add-MpPreference -ExclusionPath "C:\Program Files (x86)\Microsoft SDKs\" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just arrived here from your excellent blog post. Great job with this, and thanks for sharing! 😄