Skip to content

Commit 57cdb64

Browse files
Consume cosmos emulator from install path on agent (#19919)
Co-authored-by: Chidozie Ononiwu <[email protected]>
1 parent dedf87f commit 57cdb64

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
parameters:
2+
EmulatorInstallPath: "$(Agent.HomeDirectory)/../../Program Files/Azure Cosmos DB Emulator/Microsoft.Azure.Cosmos.Emulator.exe"
23
EmulatorMsiUrl: "https://aka.ms/cosmosdb-emulator"
34
StartParameters: ''
45

@@ -9,16 +10,7 @@ steps:
910
arguments: >
1011
-EmulatorMsiUrl "${{ parameters.EmulatorMsiUrl }}"
1112
-StartParameters "${{ parameters.StartParameters }}"
12-
-Stage "Install"
13-
pwsh: true
14-
displayName: Install Public Cosmos DB Emulator
15-
16-
- task: Powershell@2
17-
inputs:
18-
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Cosmos-Emulator.ps1
19-
arguments: >
20-
-EmulatorMsiUrl "${{ parameters.EmulatorMsiUrl }}"
21-
-StartParameters "${{ parameters.StartParameters }}"
13+
-Emulator "${{ parameters.EmulatorInstallPath }}"
2214
-Stage "Launch"
2315
pwsh: true
2416
displayName: Launch Public Cosmos DB Emulator

eng/common/scripts/Cosmos-Emulator.ps1

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ This script downloads, installs and launches cosmosdb-emulator.
99
Uri for downloading the cosmosdb-emulator
1010
1111
.PARAMETER StartParameters
12-
Parameter with which to launch the cosmosdb-emulator
12+
Parameter with which to launch the cosmosdb-emulator\
13+
14+
.PARAMETER Emulator
15+
Exact path to Microsoft.Azure.Cosmos.Emulator.exe
1316
1417
.PARAMETER Stage
1518
Determines what part of the script to run. Has to be either Install or Launch
@@ -18,6 +21,7 @@ Determines what part of the script to run. Has to be either Install or Launch
1821
Param (
1922
[string] $EmulatorMsiUrl = "https://aka.ms/cosmosdb-emulator",
2023
[string] $StartParameters,
24+
[string] $Emulator,
2125
[Parameter(Mandatory=$True)]
2226
[ValidateSet('Install', 'Launch')]
2327
[string] $Stage
@@ -26,7 +30,11 @@ Param (
2630
$targetDir = Join-Path $Env:Temp AzureCosmosEmulator
2731
$logFile = Join-Path $Env:Temp log.txt
2832
$productName = "Azure Cosmos DB Emulator"
29-
$emulator = (Join-Path $targetDir (Join-Path $productName "Microsoft.Azure.Cosmos.Emulator.exe"))
33+
34+
if ([string]::IsNullOrEmpty($Emulator))
35+
{
36+
$Emulator = (Join-Path $targetDir (Join-Path $productName "Microsoft.Azure.Cosmos.Emulator.exe"))
37+
}
3038

3139
if ($Stage -eq "Install")
3240
{
@@ -58,19 +66,19 @@ if ($Stage -eq "Install")
5866
}
5967

6068
Write-Host "Getting Cosmos DB Emulator Version"
61-
$fileVersion = Get-ChildItem $emulator
62-
Write-Host $emulator $fileVersion.VersionInfo
69+
$fileVersion = Get-ChildItem $Emulator
70+
Write-Host $Emulator $fileVersion.VersionInfo
6371
}
6472

6573
if ($Stage -eq "Launch")
6674
{
6775
Write-Host "Launching Cosmos DB Emulator"
68-
if (!(Test-Path $emulator)) {
69-
Write-Error "The emulator is not installed where expected at '$emulator'"
76+
if (!(Test-Path $Emulator)) {
77+
Write-Error "The emulator is not installed where expected at '$Emulator'"
7078
return
7179
}
7280

73-
$process = Start-Process $emulator -ArgumentList "/getstatus" -PassThru -Wait
81+
$process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait
7482
switch ($process.ExitCode) {
7583
1 {
7684
Write-Host "The emulator is already starting"
@@ -97,8 +105,8 @@ if ($Stage -eq "Launch")
97105
$argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication"
98106
}
99107

100-
Write-Host "Starting emulator process: $emulator $argumentList"
101-
$process = Start-Process $emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru
108+
Write-Host "Starting emulator process: $Emulator $argumentList"
109+
$process = Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru
102110
Write-Host "Emulator process started: $($process.Name), $($process.FileVersion)"
103111

104112
$Timeout = 600
@@ -117,7 +125,7 @@ if ($Stage -eq "Launch")
117125
}
118126

119127
do {
120-
$process = Start-Process $emulator -ArgumentList "/getstatus" -PassThru -Wait
128+
$process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait
121129
switch ($process.ExitCode) {
122130
1 {
123131
Write-Host "The emulator is starting"

0 commit comments

Comments
 (0)