共用方式為


使用 Azure Cosmos DB 模擬器組建工作,在 Azure DevOps 中設定 CI/CD 管道

適用於:NoSQL MongoDB Cassandra Gremlin 桌子

注意

由於 2022 年 4 月 1 日完全移除 Windows 2016 裝載的執行器,因此不再支援這種在 Azure DevOps 中使用 Azure Cosmos DB 模擬器與建置工作的方法。 我們正積極處理替代解決方案。 同時,您可以遵循下列指示,利用在使用「windows-2019」代理程式類型時預先安裝的Azure Cosmos DB 模擬器。

Azure Cosmos DB 模擬器提供一個模擬 Azure Cosmos DB 服務的本機環境做為開發之用。 模擬器可讓您在本機開發及測試應用程式,不需建立 Azure 訂用帳戶,也不會產生任何費用。

適用於模擬器的 PowerShell 工作

您可以編寫典型 PowerShell 型工作的指令碼,以啟動 Azure Cosmos DB 模擬器,如下所示:

作業組態的範例,選取「windows-2019」代理程式類型。 使用 windows-2019 作業設定的螢幕快照

執行啟動模擬器所需 PowerShell 指令碼的工作範例。

執行powershell腳本以啟動模擬器的螢幕快照


# Write your PowerShell commands here.

dir "$env:ProgramFiles\Azure Cosmos DB Emulator\"

Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"

$startEmulatorCmd = "Start-CosmosDbEmulator -NoFirewall -NoUI"
Write-Host $startEmulatorCmd
Invoke-Expression -Command $startEmulatorCmd

# Pipe an emulator info object to the output stream

$Emulator = Get-Item "$env:ProgramFiles\Azure Cosmos DB Emulator\Microsoft.Azure.Cosmos.Emulator.exe"
$IPAddress = Get-NetIPAddress -AddressFamily IPV4 -AddressState Preferred -PrefixOrigin Manual | Select-Object IPAddress

New-Object PSObject @{
Emulator = $Emulator.BaseName
Version = $Emulator.VersionInfo.ProductVersion
Endpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "https://${_}:8081/" }
MongoDBEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "mongodb://${_}:10255/" }
CassandraEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "tcp://${_}:10350/" }
GremlinEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "http://${_}:8901/" }
TableEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "https://${_}:8902/" }
IPAddress = $IPAddress.IPAddress
}

如果您需要使用未預先安裝 Azure Cosmos DB 模擬器的代理程式,您也可以選擇自行建置自我裝載式 Windows 代理程式。 在自我裝載式代理程式上,您可以從使用 'curl' 或 'wget' 從 https://aka.ms/cosmosdb-emulator 下載最新模擬器的 MSI 套件,然後使用 'msiexec' 加以安裝。 安裝之後,您可以執行類似上述的 PowerShell 指令碼來啟動模擬器。

下一步

若要深入了解使用模擬器來進行本機開發和測試,請參閱使用 Azure Cosmos DB 模擬器進行本機開發和測試

若要匯出模擬器 TLS/SSL 憑證,請參閱匯出 Azure Cosmos DB 模擬器憑證,以便與 Java、Python 和 Node.js 搭配使用