问题描述
我最近开始使用ARM和Azure数据工厂,现在当我尝试将ADF部署到其他环境时遇到了一个问题。由于每个环境中的源连接字符串都不同,因此我无法将静态值保留在adf.content.parameters.json文件中。 因此,我为每个环境创建了三个YML文件,分别是Dev.yml,Test.yml和Prod.yml。我有三个文件
- adf.content.json
- adf.content.parameters.json
- Dev.yml,test.yml和prod.yml
在文件adf.content.json中,我有一个连接字符串作为源。该值在每个环境中都在变化。这是adf.content.parameters.json
"parameters": {
"source_connectionString": {
"type": "securestring","Metadata": "Secure string for 'connectionString' of 'source-db'"
},
我从adf.content.parameters.json中删除了此参数,但我将其添加到了看起来像这样的Dev.yml文件中(Test.yml和prod.yml是相同的,只是不同的值)>
variables:
- name: source-connectionstring
value: <some value>
我有一个ci-build.yml和ci-deploy.yml文件,这些文件将用于CI管道。在ci-build.yml文件中,我在adf.content.json中使用了相同的名称
variables:
SourceConnectionString: $(source_connectionString:?You need to set the source_connectionString environment variable)
- stage: DevDeploy
displayName: Deploy to development (D)
variables:
- template: ../.../.../dev.yml
- group: ...
dependsOn: Build
jobs:
- template: cd_deploy.yml
parameters:
environment: dev
azureServiceConnection: '...'
containerRegistryDomain: ...
apiResourceGroup: '...'
webAppName: '...
azureSubscriptionName: ...
apimResourceGroup: ...
apimName: ...
在我的ci-deply.yml文件中看起来像这样
task: AzureResourceGroupDeployment@2
displayName: "Deploy Azure Data Factory Content"
inputs:
azureSubscription: '...'
action: '...'
resourceGroupName: '...'
location: '...'
templateLocation: '...'
csmFile: '$(System.ArtifactsDirectory)/.../arm/adf.content.json'
csmParametersFile: '$(System.ArtifactsDirectory)/../arm/adf.content.parameters.json'
overrideParameters: ' -source_connectionString$(SourceConnectionString)
deploymentMode: 'Incremental'
但是我在overrideParameters: ' -source_connectionString$(SourceConnectionString)
上收到错误消息“找不到期望的密钥”
我不知道这是否是正确的方法?以及是否有人可以得到我为什么无法获得钥匙的原因?
解决方法
此错误通常是由错误的语法引起的。
在ci-deply.yml
中,脚本overrideParameters: ' -source_connectionString$(SourceConnectionString)
丢失了'
。
因此,您在ci-deply.yml
中的任务应如下所示:
- task: AzureResourceGroupDeployment@2
displayName: "Deploy Azure Data Factory Content"
inputs:
azureSubscription: '...'
action: '...'
resourceGroupName: '...'
location: '...'
templateLocation: '...'
csmFile: '$(System.ArtifactsDirectory)/.../arm/adf.content.json'
csmParametersFile: '$(System.ArtifactsDirectory)/../arm/adf.content.parameters.json'
overrideParameters: ' -source_connectionString$(SourceConnectionString) '
deploymentMode: 'Incremental'