英文:
Continuous integration and delivery for an Azure Synapse Analytics workspace using DevOps
问题
我正在使用Azure DevOps进行持续集成和交付,用于一个Azure Synapse Analytics工作区,我需要将工作区部署到开发、测试、预生产和生产环境。这些流水线使用了参数化的LinkedServices、Datasets和Trigger。我正在遵循这些微软文档document1,document2。
我有不同的构件,需要从yaml文件中传递参数,使用TemplateParametersForWorkspace.json。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"value": "devSynapse"
},
"LinkedService_connectionString": {
"value": "Integrated Security=False;Encrypt=True;Connection Timeout=30;Data Source=;Initial Catalog="
},
"Trigger_Test_parameters_server": {
"value": "devServer"
}
}
}
请您指导我如何从DevOps CI/CD传递变量,以根据Synapse工作区部署到的环境更改这些值?
英文:
I am using Azure DevOps for continuous integration and delivery for an Azure Synapse Analytics workspace where I have deploy the workspace to Development, Test, PreProduction and Production environments. The pipelines use parametrized LinkedServices, Datasets and Trigger. I am following these Microsoft documents document1, document2.
I have these different artifacts that where I need to pass parameters from the yaml file using the TemplateParametersForWorkspace.json.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"value": "devSynapse"
},
"LinkedService_connectionString": {
"value": "Integrated Security=False;Encrypt=True;Connection Timeout=30;Data Source=;Initial Catalog="
},
"Trigger_Test_parameters_server": {
"value": "devServer"
}
}
}
I need you to point me in right direction on how to pass variables from DevOps CI/CD to change the values according to the environment the Synpase workspace is deployed to?
答案1
得分: 1
方法 1)
您可以在 ARM 模板中添加环境变量,并在管道中像下面这样使用它:-
"connectionstring": {
"type": "string"
},
"environment": {
"type": "string"
},
},
"variables": {
"storageBlobDataContributorRoleID": "ba92f5b4-2d11-453d-a403-e96b0029c9fe",
"defaultDataLakeStorageAccountUrl": "[concat('https://', parameters('defaultDataLakeStorageAccountName'), '.dfs.core.windows.net')]",
"connectionString": "[if(equals(parameters('environment'), 'Production'), parameters('connectionStringProd'), parameters('connectionStringNonProd'))]"
}
输出:-
上述参数检查,如果环境变量设置为 "Production",则使用生产连接字符串,否则使用其他环境。
方法 2)
您还可以在 Azure DevOps 管道变量的 YAML 脚本中提到每个生产环境,并在 Azure Pipelines 中像下面这样使用它:-
trigger:
- main
variables:
- name: DevEnvironment
value: "env-url"
- name: TestEnvironment
value: "env-url"
- name: PreProdEnvironment
value: "env-url"
- name: ProdEnvironment
value: "env-url"
stages:
- stage: Build
displayName: 'Build stage'
jobs:
- job: Build
displayName: 'Build job'
steps:
- script: echo 'Building the Synapse Analytics workspace...'
displayName: 'Build step'
- stage: DeployToDev
displayName: 'Deploy to Development'
dependsOn: Build
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- task: AzureResourceGroupDeployment@2
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyAzureResourceManagerConnection'
subscriptionId: '<subscription-id>'
action: 'Create Or Update Resource Group'
resourceGroupName: '<resource-group-name>'
location: '<resource-group-location>'
templateLocation: 'Linked artifact'
csmFile: '<path-to-arm-template>'
csmParametersFile: '<path-to-arm-template-parameters>'
overrideParameters: '-environment $(DevEnvironment)'
- stage: DeployToTest
displayName: 'Deploy to Test'
dependsOn: Build
condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.Reason'], 'Schedule'))
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- task: AzureResourceGroupDeployment@2
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyAzureResourceManagerConnection'
subscriptionId: '<subscription-id>'
action: 'Create Or Update Resource Group'
resourceGroupName: '<resource-group-name>'
location: '<resource-group-location>'
templateLocation: 'Linked artifact'
csmFile: '<path-to-arm-template>'
csmParametersFile: '<path-to-arm-template-parameters>'
overrideParameters: '-environment $(TestEnvironment)'
- stage: DeployToPreProd
displayName: 'Deploy to Pre-Production'
dependsOn: Build
condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.Reason'], 'Manual'))
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- task: AzureResourceGroupDeployment@2
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyAzureResourceManagerConnection'
subscriptionId: '<subscription-id>'
action: 'Create Or Update Resource Group'
resourceGroupName: '<resource-group-name>'
location: '<resource-group-location>'
templateLocation: 'Linked artifact'
csmFile: '<path-to-arm-template>'
csmParametersFile: '<path-to-arm-template-parameters>'
overrideParameters: '-environment $(PreProdEnvironment)'
- stage: DeployToProd
displayName: 'Deploy to Production'
dependsOn: Build
condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.Reason'], 'Manual'))
jobs:
- job: Deploy
displayName: 'Deploy job'
方法 3)
或者,您还可以配置不同的阶段 Dev、Test、Prod、Pre-Prod,以在特定环境中部署您的 Synapse 工作区,如下所示:-
英文:
Approach 1)
You can add Environment variable in the ARM template and use it for different environments in your pipeline like below:-
"connectionstring": {
"type": "string"
},
"environment": {
"type": "string"
}
},
"variables": {
"storageBlobDataContributorRoleID": "ba92f5b4-2d11-453d-a403-e96b0029c9fe",
"defaultDataLakeStorageAccountUrl": "[concat('https://', parameters('defaultDataLakeStorageAccountName'), '.dfs.core.windows.net')]",
"connectionString": "[if(equals(parameters('environment'), 'Production'), parameters('connectionStringProd'), parameters('connectionStringNonProd'))]"
Output:-
The above parameter checks, If the environment variable is set to Production, then it uses Production connection string or else other environment.
Approach 2)
You can also mention each production in the Azure DevOps Pipeline variables yaml script and use it in the Azure Pipelines like below:-
trigger:
- main
variables:
- name: DevEnvironment
value: "env-url"
- name: TestEnvironment
value: "env-url"
- name: PreProdEnvironment
value: "env-url"
- name: ProdEnvironment
value: "env-url"
stages:
- stage: Build
displayName: 'Build stage'
jobs:
- job: Build
displayName: 'Build job'
steps:
- script: echo 'Building the Synapse Analytics workspace...'
displayName: 'Build step'
- stage: DeployToDev
displayName: 'Deploy to Development'
dependsOn: Build
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- task: AzureResourceGroupDeployment@2
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyAzureResourceManagerConnection'
subscriptionId: '<subscription-id>'
action: 'Create Or Update Resource Group'
resourceGroupName: '<resource-group-name>'
location: '<resource-group-location>'
templateLocation: 'Linked artifact'
csmFile: '<path-to-arm-template>'
csmParametersFile: '<path-to-arm-template-parameters>'
overrideParameters: '-environment $(DevEnvironment)'
- stage: DeployToTest
displayName: 'Deploy to Test'
dependsOn: Build
condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.Reason'], 'Schedule'))
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- task: AzureResourceGroupDeployment@2
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyAzureResourceManagerConnection'
subscriptionId: '<subscription-id>'
action: 'Create Or Update Resource Group'
resourceGroupName: '<resource-group-name>'
location: '<resource-group-location>'
templateLocation: 'Linked artifact'
csmFile: '<path-to-arm-template>'
csmParametersFile: '<path-to-arm-template-parameters>'
overrideParameters: '-environment $(TestEnvironment)'
- stage: DeployToPreProd
displayName: 'Deploy to Pre-Production'
dependsOn: Build
condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.Reason'], 'Manual'))
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- task: AzureResourceGroupDeployment@2
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyAzureResourceManagerConnection'
subscriptionId: '<subscription-id>'
action: 'Create Or Update Resource Group'
resourceGroupName: '<resource-group-name>'
location: '<resource-group-location>'
templateLocation: 'Linked artifact'
csmFile: '<path-to-arm-template>'
csmParametersFile: '<path-to-arm-template-parameters>'
overrideParameters: '-environment $(PreProdEnvironment)'
- stage: DeployToProd
displayName: 'Deploy to Production'
dependsOn: Build
condition: and(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.Reason'], 'Manual'))
jobs:
- job: Deploy
displayName: 'Deploy job'
Approach 3)
Alternatively you can also configure different stages Dev, Test, Prod, Pre-Prod to deploy your Synapse workspace in specific environment like below:-
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论