Skip to content

added option to not delete the evironment(s) #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 66 additions & 28 deletions CI/Azure-DevOps/AZ_MainPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ parameters: # TODO, these don't work for scheduled pipelines, not even the defau
default:
# - name: SQL2012
# SQLVersionEdition: 2012Ent
- name: SQL2014
SQLVersionEdition: 2014
# - name: SQL2014
# SQLVersionEdition: 2014
- name: SQL2016
SQLVersionEdition: 2016
- name: SQL2017
SQLVersionEdition: 2017
- name: SQL2019
SQLVersionEdition: 2019
- name: SQL2022
SQLVersionEdition: 2022
- name: SQL2017Linux
SQLVersionEdition: 2017L
- name: SQL2019Linux
SQLVersionEdition: 2019L
- name: SQL2022Linux
SQLVersionEdition: 2022L
# - name: SQL2017
# SQLVersionEdition: 2017
# - name: SQL2019
# SQLVersionEdition: 2019
# - name: SQL2022
# SQLVersionEdition: 2022
# - name: SQL2017Linux
# SQLVersionEdition: 2017L
# - name: SQL2019Linux
# SQLVersionEdition: 2019L
# - name: SQL2022Linux
# SQLVersionEdition: 2022L
- name: CreateEnvOnly
displayName: Create Environment Only
default: false
type: boolean
- name: VMPriority
displayName: VM Priority
type: string
Expand Down Expand Up @@ -221,14 +225,12 @@ stages:
# $SerializedVMDetails;

#-----------------------------------------------------------------------#
# IMPORTANT (and, you've got to be kidding me): #
# The space below is absolutely required to make the ANT Task work. #
# The space below is required to make ANT work. (Not currently in use.) #
#---------------------------------------|-------------------------------#
$FQDNAndPort = $VMDetails.SQLVmFQDN + ", " + $VMDetails.SQLVmPort;
#---------------------------------------|-------------------------------#
#-----------------------------------------------------------------------#

#TODO refactor such that the resourcegroupname is created in a previous step, so that it can be used by the delete job, even if this one is cancelled/failed.
$ResourceGroupName = $VMDetails.ResourceGroupName;
Write-Host "##vso[task.setvariable variable=SQLUserName;isOutput=true]$SQLUserName"
Write-Host "##vso[task.setvariable variable=SQLPwd;isOutput=true]$SQLPwd"
Expand All @@ -238,17 +240,54 @@ stages:
# Write-Host "##vso[task.setvariable variable=SerializedVMDetails;isOutput=true]$SerializedVMDetails";


- job: PrintSQLInfo
dependsOn: Create
strategy:
matrix:
${{ each version in parameters.VMMatrix }}:
${{ format('{0}', version.name) }}:
SQLVersionEdition: ${{ version.SQLVersionEdition }}
SQLVersionName: ${{ version.name }}
variables:
databaseAccessDetails: $[convertToJson(dependencies.Create.outputs)]
steps:
- checkout: none
- task: PowerShell@2
name: PrintSQLVersionInfo
env:
USER_NAME: $(tSQLt-UserForCIEnvironment-UserName)
PASSWORD: $(tSQLt-UserForCIEnvironment-Password)
name: PrintSQLInfo
inputs:
targetType: 'inline'
script: |
$DS = Invoke-Sqlcmd -Query "SELECT SUSER_NAME() U,SYSDATETIME() T,@@VERSION V;" -ServerInstance "$(CreateSQLVMEnvironment.FQDNAndPort)" -Username "$(CreateSQLVMEnvironment.SQLUserName)" -Password "$(CreateSQLVMEnvironment.SQLPwd)" -As DataSet -TrustServerCertificate
$inputObject = @'
$(databaseAccessDetails)
'@;
$myJsonObject = ConvertFrom-JSON -InputObject $inputObject;
$SQLUserNameKey = "$(System.JobName).CreateSQLVMEnvironment.SQLUserName";
$SQLPwdKey = "$(System.JobName).CreateSQLVMEnvironment.SQLPwd";
$FQDNAndPortKey = "$(System.JobName).CreateSQLVMEnvironment.FQDNAndPort";
$SQLUserName = $myJsonObject.$SQLUserNameKey;
$SQLPwd = $myJsonObject.$SQLPwdKey;
$FQDNAndPort = $myJsonObject.$FQDNAndPortKey;

$DS = Invoke-Sqlcmd -Query "SELECT SUSER_NAME() U,SYSDATETIME() T,@@VERSION V;" -ServerInstance "$FQDNAndPort" -Username "$SQLUserName" -Password "$SQLPwd" -As DataSet -TrustServerCertificate
$DS.Tables[0].Rows | %{ echo "{ $($_['U']), $($_['T']), $($_['V']) }" }

if("${{ parameters.CreateEnvOnly }}" -ieq "true"){
Write-Host '==========================================================' -ForegroundColor Yellow;
Write-Host "Name: $(SQLVersionName)";
Write-Host "FQDN: $FQDNAndPort";
Write-Host "User: $SQLUserName";
Write-Host "Pass: $SQLPwd";
Write-Host '==========================================================' -ForegroundColor Yellow;

Write-Warning 'This information is now public! Run the following Powershell Statement to change the password immediately!';

$PwdChngCommand = "`$NewPwd = -join ((40..95+97..126) | Get-Random -Count 40 | % {[char]`$_}); Write-Output `"New Password: `$NewPwd`"; Invoke-Sqlcmd -Query `"ALTER LOGIN [$SQLUserName] WITH PASSWORD = '`$NewPwd';`" -ServerInstance `"$FQDNAndPort`" -Username `"$SQLUserName`" -Password `"$SQLPwd`" -TrustServerCertificate;";
Write-Host '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - ' -ForegroundColor Yellow;
Write-Host $PwdChngCommand
Write-Host '==========================================================' -ForegroundColor Yellow;

}


##########################################################################################################
## BUILD tSQLt - PART 1 ##
Expand All @@ -257,6 +296,7 @@ stages:

- stage: Build_tSQLt_Part1
dependsOn: [] # this removes the implicit dependency on previous stage and causes this to run in parallel
condition: eq(${{ parameters.CreateEnvOnly }}, false)

jobs:

Expand Down Expand Up @@ -395,9 +435,6 @@ stages:
${{ format('{0}', version.name) }}:
SQLVersionEdition: ${{ version.SQLVersionEdition }}

pool:
vmImage: 'windows-latest'

variables:
databaseAccessDetails: $[convertToJson(stageDependencies.Create_Environments.Create.outputs)]

Expand Down Expand Up @@ -805,20 +842,21 @@ stages:
dependsOn:
- Create_Environments
- Validate
condition: always()

condition: not(eq(${{ parameters.CreateEnvOnly }}, true))

pool:
vmImage: 'windows-latest'

jobs:

- job: Delete_VM

strategy:
matrix:
${{ each version in parameters.VMMatrix }}:
${{ format('{0}', version.name) }}:
SQLVersionEdition: ${{ version.SQLVersionEdition }}

variables:
databaseAccessDetails: $[convertToJson(stageDependencies.Create_Environments.Create.outputs)]

Expand Down