mirror of
https://github.com/actions/runner-images.git
synced 2026-01-06 01:59:46 +08:00
Merge pull request #568 from Darleev/v-danurg/install_sql_express
Add Microsoft SQL Server Express to Windows VMs
This commit is contained in:
78
images/win/scripts/Installers/Install-SQLExpress.ps1
Normal file
78
images/win/scripts/Installers/Install-SQLExpress.ps1
Normal file
@@ -0,0 +1,78 @@
|
||||
################################################################################
|
||||
## File: Install-SQLExpress.ps1
|
||||
## Desc: Install SQL Express for Windows
|
||||
################################################################################
|
||||
Import-Module -Name ImageHelpers -Force;
|
||||
|
||||
function Download-FullSQLPackage {
|
||||
param(
|
||||
[String]$InstallerPath,
|
||||
[String]$DownloadPath,
|
||||
[String]$Arguments = ("/MEDIAPATH=$DownloadPath", "/MEDIATYPE=Core","/Action=Download", "/QUIET")
|
||||
)
|
||||
Write-Host "Downloading full package to $DownloadPath..."
|
||||
$process = Start-Process -FilePath $InstallerPath -ArgumentList $Arguments -Wait -PassThru
|
||||
$exitCode = $process.ExitCode
|
||||
if ($exitCode -eq 0)
|
||||
{
|
||||
Write-Host -Object "Full SQL Express package has been successfully downloaded to $DownloadPath : ExitCode: $exitCode"
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -Object "Full package downloading process was unsuccessful. Exit code: $exitCode."
|
||||
exit $exitCode
|
||||
}
|
||||
}
|
||||
|
||||
function Unpack-SQLInstaller {
|
||||
param(
|
||||
[String]$InstallPath,
|
||||
[String]$Arguments = ("/Q", "/IACCEPTSQLSERVERLICENSETERMS")
|
||||
)
|
||||
Write-Host "Start unpacking procedure to $InstallPath..."
|
||||
$process = Start-Process -FilePath $InstallPath -ArgumentList $Arguments -Wait -PassThru
|
||||
$exitCode = $process.ExitCode
|
||||
# Exit code -2067529716 is added since SQL Unpack procedure returns it on success.
|
||||
if ($exitCode -eq 0 -or $exitCode -eq -2067529716)
|
||||
{
|
||||
Write-Host -Object "SQL installer unpacking has been completed."
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -Object "SQL installer unpacking was interrupted : $exitCode."
|
||||
exit $exitCode
|
||||
}
|
||||
}
|
||||
|
||||
function Start-Installer {
|
||||
param(
|
||||
[String]$InstallerPath,
|
||||
[String]$Arguments = ("/Q", "/IACCEPTSQLSERVERLICENSETERMS", "/Action=Install", "/INSTANCEID=SQL2019", "/INSTANCENAME=SQL2019", "/SECURITYMODE=SQL", "/SAPWD=P@ssword!!", "/TCPENABLED=1")
|
||||
)
|
||||
Write-Host "Installating SQL Express..."
|
||||
$process = Start-Process -FilePath $InstallerPath -ArgumentList $Arguments -Wait -PassThru
|
||||
$exitCode = $process.ExitCode
|
||||
if ($exitCode -eq 0)
|
||||
{
|
||||
Write-Host -Object "SQL Express has been successfully installed: ExitCode: $exitCode"
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host -Object "Installation procedure was not correctly completed. Exit code: $exitCode."
|
||||
exit $exitCode
|
||||
}
|
||||
}
|
||||
#Main function
|
||||
$installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658"
|
||||
$downloadPath = "C:\SQLInstall"
|
||||
$setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU"
|
||||
#Create directory for temporary files
|
||||
New-Item -Path $downloadPath -ItemType Directory
|
||||
Set-Location -Path $downloadPath
|
||||
$installerPath = Start-DownloadWithRetry -Url $installerUrl -DownloadPath $downloadPath -Name "SQL2019-SSEI-Expr.exe"
|
||||
Download-FullSQLPackage -InstallerPath $installerPath -DownloadPath $downloadPath
|
||||
Unpack-SQLInstaller -InstallPath "$setupPath.exe"
|
||||
$resultPath = Join-Path $setupPath "SETUP.exe"
|
||||
Start-Installer -InstallerPath $resultPath
|
||||
#Cleanup folder with installation packages.
|
||||
Remove-Item $downloadPath -Recurse -Force
|
||||
52
images/win/scripts/Installers/Validate-SQLExpress.ps1
Normal file
52
images/win/scripts/Installers/Validate-SQLExpress.ps1
Normal file
@@ -0,0 +1,52 @@
|
||||
################################################################################
|
||||
## File: Validate-SQLExpress.ps1
|
||||
## Desc: Validate Microsoft SQL Express installation
|
||||
################################################################################
|
||||
|
||||
#Parameters for database access
|
||||
$sqlUser = "sa"
|
||||
$sqlPassword = "P@ssword!!"
|
||||
$sqlInstance = "SQL2019"
|
||||
|
||||
function Test-SqlConnection {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$ServerName,
|
||||
[Parameter(Mandatory)]
|
||||
[string]$IntegratedSecurity,
|
||||
[Parameter(Mandatory)]
|
||||
[string]$UserName,
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Password
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
try {
|
||||
$connectionString = 'Server={0};Integrated Security={1};User ID={2};Password={3}' -f $ServerName,$IntegratedSecurity,$UserName,$Password
|
||||
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
|
||||
$sqlConnection.Open()
|
||||
Write-Host -Object "Connection to SQL Express was successful."
|
||||
return $sqlConnection.ServerVersion
|
||||
|
||||
} catch {
|
||||
Write-Host -Object "Connection to SQL Express cannot be established."
|
||||
exit 1
|
||||
|
||||
} finally {
|
||||
## Close the connection when we're done
|
||||
$sqlConnection.Close()
|
||||
}
|
||||
}
|
||||
$instanceName = "$env:computername\$sqlInstance"
|
||||
$version = Test-SqlConnection -ServerName $instanceName -IntegratedSecurity "false" -UserName $sqlUser -Password $sqlPassword
|
||||
|
||||
# Adding description of the software to Markdown
|
||||
$SoftwareName = "Git"
|
||||
$Description = @"
|
||||
_Version:_ $version<br/>
|
||||
_InstanceName:_ $sqlInstance<br/>
|
||||
_Username:_ $sqlUser<br/>
|
||||
_Password:_ $sqlPassword<br/>
|
||||
_Default Path:_ C:\Program Files (x86)\Microsoft SQL Server
|
||||
"@
|
||||
|
||||
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description
|
||||
Reference in New Issue
Block a user