aboutsummaryrefslogtreecommitdiffstats
path: root/it/packer/setup.ps1
blob: bfaca0273bd8cf0e364ab597a7447ba1ab3025e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$ErrorActionPreference = 'Stop'

function Install-Chocolatey {
  # Run the installer.
  Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}

function Install-NodeJs {
  choco install -y nodejs
}

function Install-Buildtools {
  $path = "${env:Temp}\buildTools.zip"

  # Fetch the build tools archive.
  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  (New-Object System.Net.WebClient).DownloadFile('https://github.com/SonarSource/buildTools/archive/docker.zip', $path)

  # Extract the archive to the C drive.
  Add-Type -AssemblyName System.IO.Compression.FileSystem
  [System.IO.Compression.ZipFile]::ExtractToDirectory($path, 'C:\')

  # Update global PATH.
  $currentPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
  $updatedPath = $currentPath+';C:\buildTools-docker\bin'
  Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $updatedPath

  # Remove archive.
  del $path
}

function Install-Maven {
  choco install -y openjdk11 --version 11.0.4.11
  choco install -y maven --version 3.6.2
}

function Install-Git {
  # We use Git to enable Unix Tools. This will allow us to use Bash-style
  # commands in .cirrus.yml, like "source".
  choco install -y git --version 2.23.0 --package-parameters "/GitAndUnixToolsOnPath"
}

Write-Host "Install chocolatey"
Install-Chocolatey

Write-Host "Install Maven"
Install-Maven

Write-Host "Install NodeJs"
Install-NodeJs

Write-Host "Install Unix Tools"
Install-Git

Write-Host "Set up build tools"
Install-Buildtools

# Disable antivirus analysis on C drive.
Write-Host "Finalize VM configuration"
Set-MpPreference -ScanAvgCPULoadFactor 5 -ExclusionPath "C:\"