Skip to content

Commit e94bb69

Browse files
authored
Fix forked repo local SQL Server passwords (#3950)
1 parent 28caf4c commit e94bb69

15 files changed

Lines changed: 623 additions & 480 deletions

eng/pipelines/common/templates/jobs/ci-run-tests-job.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ parameters:
116116
type: boolean
117117
default: false
118118

119+
# The SA password to set when configuring SQL Server.
120+
- name: saPassword
121+
type: string
122+
119123
jobs:
120124
- job: ${{ format('{0}', coalesce(parameters.jobDisplayName, parameters.image, 'unknown_image')) }}
121125

@@ -179,6 +183,7 @@ jobs:
179183
- template: /eng/pipelines/common/templates/steps/update-config-file-step.yml@self # update config.json file
180184
parameters:
181185
debug: ${{ parameters.debug }}
186+
saPassword: ${{ parameters.saPassword }}
182187
UseManagedSNIOnWindows: ${{ parameters.usemanagedSNI }}
183188
${{ if parameters.configProperties.TCPConnectionString }}:
184189
TCPConnectionString: ${{ parameters.configProperties.TCPConnectionString }}
@@ -255,6 +260,7 @@ jobs:
255260
parameters:
256261
operatingSystem: ${{ parameters.operatingSystem }}
257262
netcoreVersionTestUtils: ${{ parameters.netcoreVersionTestUtils }}
263+
saPassword: ${{ parameters.saPassword }}
258264
${{ if parameters.configProperties.instanceName }}:
259265
instanceName: ${{ parameters.configProperties.instanceName }}
260266
${{ if parameters.configProperties.user }}:

eng/pipelines/common/templates/jobs/run-tests-package-reference-job.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343

4444
- template: /eng/pipelines/common/templates/steps/update-config-file-step.yml
4545
parameters:
46+
# We use the Library $(Password) variable as the SA password in this pipeline.
47+
saPassword: $(Password)
4648
TCPConnectionString: $(SQL_TCP_CONN_STRING)
4749
NPConnectionString: $(SQL_NP_CONN_STRING)
4850
SupportsIntegratedSecurity: false

eng/pipelines/common/templates/stages/ci-run-tests-stage.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
# The .NET Foundation licenses this file to you under the MIT license. #
44
# See the LICENSE file in the project root for more information. #
55
#################################################################################
6+
7+
# This stage depends on the secrets_stage.
8+
69
parameters:
710
- name: abstractionsArtifactsName
811
type: string
912

1013
- name: abstractionsPackageVersion
1114
type: string
1215

16+
- name: additionalDependsOn
17+
type: object
18+
default: []
19+
1320
- name: buildConfiguration
1421
type: string
1522
values:
@@ -20,10 +27,6 @@ parameters:
2027
type: boolean
2128
default: false
2229

23-
- name: dependsOn
24-
type: object
25-
default: []
26-
2730
- name: mdsArtifactsName
2831
type: string
2932
default: MDS.Artifacts
@@ -56,7 +59,16 @@ stages:
5659
- ${{ each config in parameters.testConfigurations }}:
5760
- ${{ each image in config.value.images }}:
5861
- stage: ${{ image.key }}
59-
dependsOn: ${{ parameters.dependsOn }}
62+
dependsOn:
63+
- secrets_stage
64+
- ${{ each dep in parameters.additionalDependsOn }}:
65+
- ${{ dep }}
66+
67+
variables:
68+
# Bring the SA password from the secrets_stage into scope here.
69+
- name: saPassword
70+
value: $[stageDependencies.secrets_stage.secrets_job.outputs['SaPassword.Value']]
71+
6072
jobs:
6173
- ${{ each targetFramework in config.value.TargetFrameworks }}:
6274
- ${{ each platform in config.value.buildPlatforms }}:
@@ -87,6 +99,7 @@ stages:
8799
configSqlFor: ${{ config.value.configSqlFor }}
88100
operatingSystem: ${{ config.value.operatingSystem }}
89101
isArm64: ${{ eq(config.value.isArm64, 'true') }}
102+
saPassword: $(saPassword)
90103
${{if ne(config.value.configProperties, '{}') }}:
91104
${{ each x86TF in config.value.configProperties.x86TestTargetFrameworks }}:
92105
${{ if eq(x86TF, targetFramework) }}:
@@ -123,6 +136,7 @@ stages:
123136
configSqlFor: ${{ config.value.configSqlFor }}
124137
operatingSystem: ${{ config.value.operatingSystem }}
125138
isArm64: ${{ eq(config.value.isArm64, 'true') }}
139+
saPassword: $(saPassword)
126140
${{if and(eq(usemanagedSNI, false), ne(config.value.configProperties, '{}')) }}:
127141
${{ each x86TF in config.value.configProperties.x86TestTargetFrameworks }}:
128142
${{ if eq(x86TF, targetFramework) }}:

eng/pipelines/common/templates/steps/configure-sql-server-linux-step.yml

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,51 @@
77
# This step configures an existing SQL Server running on the local Linux host. For example, our 1ES
88
# Hosted Pool has images like ADO-UB20-SQL22 that come with SQL Server 2022 pre-installed and
99
# running.
10-
#
11-
# The SA password is set to the value of the $(Password) variable defined in the ADO Library "ADO
12-
# Test Configuration properties", brought in by common/templates/libraries/ci-build-variables.yml.
1310

1411
parameters:
15-
- name: condition
12+
13+
# The SA password to set when configuring SQL Server.
14+
- name: saPassword
1615
type: string
17-
default: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
1816

1917
steps:
20-
# Linux only steps
21-
- bash: |
22-
sudo systemctl stop mssql-server
23-
24-
# Password for the SA user (required)
25-
26-
MSSQL_SA_PW="$(Password)"
27-
28-
# Product ID of the version of SQL server you're installing
29-
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
30-
MSSQL_PID="enterprise"
31-
32-
echo Running mssql-conf setup...
33-
sudo MSSQL_SA_PASSWORD="$MSSQL_SA_PW" \
34-
MSSQL_PID="$MSSQL_PID" \
35-
/opt/mssql/bin/mssql-conf -n setup accept-eula
36-
37-
# Connect to server and get the version:
38-
counter=1
39-
errstatus=1
40-
while [ $counter -le 5 ] && [ $errstatus = 1 ]
41-
do
42-
echo Waiting for SQL Server to start...
43-
sleep 3s
44-
/opt/mssql-tools/bin/sqlcmd \
45-
-S localhost \
46-
-U SA \
47-
-P $MSSQL_SA_PW\
48-
-Q "SELECT @@VERSION" 2>/dev/null
49-
errstatus=$?
50-
((counter++))
51-
done
52-
53-
# Display error if connection failed:
54-
if [ $errstatus = 1 ]
55-
then
56-
echo Cannot connect to SQL Server, installation aborted
57-
exit $errstatus
58-
fi
59-
displayName: 'Configure SQL Server [Linux]'
60-
condition: ${{parameters.condition }}
18+
19+
# Configure SQL Server.
20+
- bash: |
21+
sudo systemctl stop mssql-server
22+
23+
# Password for the SA user (required)
24+
MSSQL_SA_PW="${{ parameters.saPassword }}"
25+
26+
# Product ID of the version of SQL server you're installing
27+
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
28+
MSSQL_PID="enterprise"
29+
30+
echo Running mssql-conf setup...
31+
sudo MSSQL_SA_PASSWORD="$MSSQL_SA_PW" \
32+
MSSQL_PID="$MSSQL_PID" \
33+
/opt/mssql/bin/mssql-conf -n setup accept-eula
34+
35+
# Connect to server and get the version:
36+
counter=1
37+
errstatus=1
38+
while [ $counter -le 5 ] && [ $errstatus = 1 ]
39+
do
40+
echo Waiting for SQL Server to start...
41+
sleep 3s
42+
/opt/mssql-tools/bin/sqlcmd \
43+
-S localhost \
44+
-U SA \
45+
-P "$MSSQL_SA_PW" \
46+
-Q "SELECT @@VERSION" 2>/dev/null
47+
errstatus=$?
48+
((counter++))
49+
done
50+
51+
# Display error if connection failed:
52+
if [ $errstatus = 1 ]
53+
then
54+
echo Cannot connect to SQL Server, installation aborted
55+
exit $errstatus
56+
fi
57+
displayName: 'Configure SQL Server [Linux]'

0 commit comments

Comments
 (0)