Last active
December 23, 2020 07:02
-
-
Save davidroberts63/7159913 to your computer and use it in GitHub Desktop.
Installing Jenkins for .NET builds
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
<# | |
.NET 4.5 Build Installation script | |
(run with administrative rights) | |
You can get the netfx45_dtp.msi (and .cab file) by downloading the Windows SDK | |
http://msdn.microsoft.com/en-us/windows/hardware/hh852363.aspx | |
Run the sdk and have the installer download the files for later use. | |
You can get the vs_isoshell.exe by downloading the Visual Studio Isolated Shell. | |
http://www.visualstudio.com/downloads/download-visual-studio-vs (That's for 2013) | |
Run the installer and you will have the Microsoft.WebApplication.Targets file. | |
#> | |
param( | |
[string]$dotNetInstaller = ".\dotnetfx45_full_x86_x64.exe", | |
[string]$toolsInstaller = "netfx45_dtp.msi", | |
[string]$isolatedShellInstaller = ".\vs_isoshell.exe" | |
) | |
function Is-Framework45Installed() | |
{ | |
# Credit goes to: http://stackoverflow.com/questions/3487265/powershell-to-return-versions-of-net-framework-on-a-machine#3495491 | |
$frameworks = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | ` | |
Get-ItemProperty -name Version -EA 0 | ` | |
Where { $_.PSChildName -match '^(?!S)\p{L}'} | ` | |
Foreach { $_.Version } | |
return $frameworks -contains "4.5.50709" | |
} | |
function Install-Framework45() | |
{ | |
if (Is-Framework45Installed) | |
{ | |
Write-Host .NET Framework version $latestFrameworkVersion already appears to be installed. | |
} | |
else | |
{ | |
if (Test-Path $dotNetInstaller) | |
{ | |
Write-Host Installing .NET Framework 4.5 | |
Start-Process $dotNetInstaller "/passive frameworklog.txt /norestart" -Wait -Verb RunAs | |
} | |
else | |
{ | |
throw ".NET Framework 4.5 installer doesn't seem to exist. Looked for it at $dotNetInstaller" | |
} | |
} | |
} | |
function Is-BuildToolsInstalled() | |
{ | |
return Test-Path "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5" | |
} | |
function Install-BuildTools() | |
{ | |
if (Is-BuildToolsInstalled) | |
{ | |
Write-Host Build tools appear to be already installed. | |
} | |
else | |
{ | |
Write-Host Installing .NET Framework 4.5 build tools | |
$args = "/i `"" + $toolsInstaller + "`" EXTUI=1 /q /log toolslog.txt" | |
Start-Process "msiexec.exe" $args -Wait -Verb RunAs | |
} | |
} | |
function Is-IsolatedShellInstalled() | |
{ | |
return Test-Path "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" | |
} | |
function Install-IsolatedShell() | |
{ | |
if (Is-IsolatedShellInstalled) | |
{ | |
Write-Host Isolated Shell appear to be already installed. Skipping | |
} | |
else | |
{ | |
Write-Host Installing Isolated Shell | |
Start-Process $isolatedShellInstaller "/passive /log isolatedShelllog.txt /norestart" -Wait -Verb RunAs | |
} | |
} | |
Install-Framework45 | |
Install-BuildTools | |
Install-IsolatedShell | |
Write-Host Done |
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
<# | |
Jenkins-CI Installation script | |
(run with administrative rights) | |
#> | |
param( | |
[string]$jenkinsInstaller = "jenkins-1.531.msi", | |
[string]$jenkinsInstallDir = "C:\Programs\jenkins", | |
[string]$jenkinsConfigSourceDir = ".\config-files", | |
[string]$jenkinsPluginsSourceDir = ".\plugins", | |
) | |
function Is-JenkinsInstalled | |
{ | |
return (Get-Service | Where-Object { $_.Name -eq "Jenkins" }) -ne $null | |
} | |
function Install-JenkinsCI | |
{ | |
if (Is-JenkinsInstalled) | |
{ | |
Write-Host Jenkins CI appears to be installed. | |
} | |
else | |
{ | |
if (Test-Path $jenkinsInstaller) | |
{ | |
Write-Host Installing Jenkins CI | |
$commandArgs = "/i $jenkinsInstaller /quiet JENKINSDIR=$jenkinsInstallDir /lv jenkins-install-Write-Host.txt" | |
Start-Process "msiexec" $commandArgs -Wait -Verb RunAs | |
Write-Host Waiting for post-install Jenkins processing | |
# After msiexec has completed there seems to be additional processing by jenkins. Likely from the service. | |
# Additional file and folders continue to be created even after the installer is complete. This causes problems if later | |
# steps (namely plugin installation) occurs before the post-install processing is complete. | |
Start-Sleep -S 30 | |
} | |
else | |
{ | |
throw Cannot find Jenkins CI installer at $jenkinsInstaller | |
} | |
} | |
} | |
function Set-JenkinsConfiguration | |
{ | |
Write-Host Updating jenkins configuration | |
Stop-Service Jenkins | |
if (Test-Path $jenkinsConfigSourceDir) | |
{ | |
Write-Host Copying jenkins configuration files from $jenkinsConfigSourceDir | |
Copy $jenkinsConfigSourceDir\*.* $jenkinsInstallDir -force | |
} | |
else | |
{ | |
throw The source for config files was not found. $jenkinsConfigSourceDir | |
} | |
Start-Service Jenkins | |
} | |
function Install-Plugins | |
{ | |
Write-Host Installing jenkins plugins | |
Stop-Service Jenkins | |
if (Test-Path $jenkinsPluginsSourceDir) | |
{ | |
Write-Host Copying plugin files from $jenkinsPluginsSourceDir | |
Copy $jenkinsPluginsSourceDir\*.hpi $jenkinsInstallDir\plugins | |
} | |
else | |
{ | |
throw The source for plugin files was not found. $jenkinsPluginsSourceDir | |
} | |
Start-Service Jenkins | |
} | |
$ErrorActionPreference = "stop" | |
Install-JenkinsCI | |
Install-Plugins | |
Set-JenkinsConfiguration | |
Write-Host "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment