我有一个带有两个数据源连接的表格模型。两个数据源都连接到不同的服务器(和数据库)以检索模型中表的数据。在 Azure DevOps 中,我创建了一个发布管道,以使用“表格数据库部署”步骤将 model.bim 文件部署到我的 Azure 分析服务器。
在此步骤中,您可以指定“数据源类型”。由于我有两个数据源,因此我选择了“高级(多个连接)”。在此字段下的“高级数据源安全设置”中,我需要提供每个数据源的凭据。如果我不这样做并尝试处理模型中的表,我会收到一条错误,指示未正确提供凭据。
在“表格数据库部署”步骤之前,我的管道中还有另外两项任务。一个是从我的 Azure Key Vault 检索数据,另一个是 Azure CLI 任务,用于获取我的服务连接的详细信息。 “表格数据库部署”是最后一步。
我已在“高级数据源安全设置”中尝试了以下操作:
[
{
"type": "structured",
"name": "TEST1",
"connectionDetails": {
"protocol": "tds",
"address": {
"server": "room1.net",
"database": "Test_db1"
},
"authentication": null,
"query": null
},
"credential": {
"AuthenticationKind": "UsernamePassword",
"kind": "SQL",
"Username": "bla1",
"EncryptConnection": true,
"Password": "$(DS1_PASSWORD)"
}
},
{
"type": "structured",
"name": "TEST2",
"connectionDetails": {
"protocol": "tds",
"address": {
"server": "room2.net",
"database": "Test_db2"
},
"authentication": null,
"query": null
},
"credential": {
"AuthenticationKind": "UsernamePassword",
"kind": "SQL",
"Username": "bla2",
"EncryptConnection": true,
"Password": "$(DS2_PASSWORD)"
}
}
]
我收到以下错误:传入的对象无效,需要“:”或“}”。
我尝试了一切,询问ChatGPT等,但我不知道该怎么办。我似乎无法传递凭据。该秘密存储在我的 Azure Key Vault 中,这就是我使用该变量的原因。
解决方案:我想处理来自不同数据源的表。我通过 Azure DevOps 发布管道传递的凭据必须包含在我的部署中。
谁可以帮助我?我将不胜感激,因为我已经坚持了几天了。
最后一步的完整 YAML,按照 @Kevin Lu-MSFT 的要求
steps:
- task: liprec.vsts-release-aas.deploy-aas-db.deploy-aas-db@1
displayName: 'blabla1'
inputs:
connectedServiceNameSelector: connectedServiceNameARM
connectedServiceNameARM: 'ppppp'
aasServer: 'pppppp.net'
databaseName: 'test11_tabular'
loginType: spn
tenantId: '$(tenantId)'
appId: '$(servicePrincipalId)'
appKey: '$(servicePrincipalKey)'
pathToModel: '$(System.DefaultWorkingDirectory)/aa/Model/test11_Tabular/bin/Model.asdatabase'
partitionDeployment: deploypartitions
roleDeployment: deployrolesandmembers
connectionType: advanced
datasources: |
[
{
"type": "structured",
"name": "TEST1",
"connectionDetails": {
"protocol": "tds",
"address": {
"server": "room1.net",
"database": "Test_db1"
},
"authentication": null,
"query": null
},
"credential": {
"AuthenticationKind": "UsernamePassword",
"kind": "SQL",
"Username": "bla1",
"EncryptConnection": true,
"Password": "$(DS1_PASSWORD)"
}
},
{
"type": "structured",
"name": "TEST2",
"connectionDetails": {
"protocol": "tds",
"address": {
"server": "room2.net",
"database": "Test_db2"
},
"authentication": null,
"query": null
},
"credential": {
"AuthenticationKind": "UsernamePassword",
"kind": "SQL",
"Username": "bla2",
"EncryptConnection": true,
"Password": "$(DS2_PASSWORD)"
}
}
]
overwrite: false
正如评论中提到的,
$(DS1_PASSWORD)
和$(DS2_PASSWORD)
变量可能包含需要转义的值,例如"
(双引号)。
我建议添加一个额外的任务来将这些变量编码为正确的 json 字符串,然后在
liprec.vsts-release-aas.deploy-aas-db.deploy-aas-db@1
任务中使用编码值。
示例:
steps:
- pwsh: |
$DS1_PASSWORD_JSON = (${Env:DS1_PASS} | ConvertTo-Json -Compress).Trim()
$DS2_PASSWORD_JSON = (${Env:DS2_PASS} | ConvertTo-Json -Compress).Trim()
Write-Host "##vso[task.setvariable variable=DS1_PASSWORD_JSON]$DS1_PASSWORD_JSON"
Write-Host "##vso[task.setvariable variable=DS2_PASSWORD_JSON]$DS2_PASSWORD_JSON"
displayName: Encode passwords
env:
# use environment variables to avoid handling special characters in the script body
DS1_PASS: $(DS1_PASSWORD)
DS2_PASS: $(DS2_PASSWORD)
- script: |
echo "DS1_PASSWORD_JSON: $(DS1_PASSWORD_JSON)"
echo "DS2_PASSWORD_JSON: $(DS2_PASSWORD_JSON)"
displayName: Second output passwords
# use DS1_PASSWORD_JSON and DS2_PASSWORD_JSON variables
# instead of DS1_PASSWORD and DS2_PASSWORD
- task: liprec.vsts-release-aas.deploy-aas-db.deploy-aas-db@1
displayName: 'blabla1'
inputs:
connectedServiceNameSelector: connectedServiceNameARM
connectedServiceNameARM: 'ppppp'
aasServer: 'pppppp.net'
databaseName: 'test11_tabular'
loginType: spn
tenantId: '$(tenantId)'
appId: '$(servicePrincipalId)'
appKey: '$(servicePrincipalKey)'
pathToModel: '$(System.DefaultWorkingDirectory)/aa/Model/test11_Tabular/bin/Model.asdatabase'
partitionDeployment: deploypartitions
roleDeployment: deployrolesandmembers
connectionType: advanced
datasources: |
[
{
"type": "structured",
"name": "TEST1",
"connectionDetails": {
"protocol": "tds",
"address": {
"server": "room1.net",
"database": "Test_db1"
},
"authentication": null,
"query": null
},
"credential": {
"AuthenticationKind": "UsernamePassword",
"kind": "SQL",
"Username": "bla1",
"EncryptConnection": true,
"Password": "$(DS1_PASSWORD_JSON)"
}
},
{
"type": "structured",
"name": "TEST2",
"connectionDetails": {
"protocol": "tds",
"address": {
"server": "room2.net",
"database": "Test_db2"
},
"authentication": null,
"query": null
},
"credential": {
"AuthenticationKind": "UsernamePassword",
"kind": "SQL",
"Username": "bla2",
"EncryptConnection": true,
"Password": "$(DS2_PASSWORD_JSON)"
}
}
]
overwrite: false