在 Azure Synapse Analytics 工作区中使用 DevOps 进行持续集成和交付

huangapple go评论64阅读模式
英文:

Continuous integration and delivery for an Azure Synapse Analytics workspace using DevOps

问题

我正在使用Azure DevOps进行持续集成和交付,用于一个Azure Synapse Analytics工作区,我需要将工作区部署到开发、测试、预生产和生产环境。这些流水线使用了参数化的LinkedServices、Datasets和Trigger。我正在遵循这些微软文档document1document2

我有不同的构件,需要从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.

在 Azure Synapse Analytics 工作区中使用 DevOps 进行持续集成和交付

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'))]"
}

输出:-

在 Azure Synapse Analytics 工作区中使用 DevOps 进行持续集成和交付

上述参数检查,如果环境变量设置为 "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 工作区,如下所示:-

在 Azure Synapse Analytics 工作区中使用 DevOps 进行持续集成和交付

英文:

Approach 1)

You can add Environment variable in the ARM template and use it for different environments in your pipeline like below:-

&quot;connectionstring&quot;: {

&quot;type&quot;: &quot;string&quot;

},

&quot;environment&quot;: {

&quot;type&quot;: &quot;string&quot;

}

},

&quot;variables&quot;: {

&quot;storageBlobDataContributorRoleID&quot;: &quot;ba92f5b4-2d11-453d-a403-e96b0029c9fe&quot;,

&quot;defaultDataLakeStorageAccountUrl&quot;: &quot;[concat(&#39;https://&#39;, parameters(&#39;defaultDataLakeStorageAccountName&#39;), &#39;.dfs.core.windows.net&#39;)]&quot;,

&quot;connectionString&quot;: &quot;[if(equals(parameters(&#39;environment&#39;), &#39;Production&#39;), parameters(&#39;connectionStringProd&#39;), parameters(&#39;connectionStringNonProd&#39;))]&quot;

Output:-

在 Azure Synapse Analytics 工作区中使用 DevOps 进行持续集成和交付

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: &quot;env-url&quot;
  - name: TestEnvironment
    value: &quot;env-url&quot;
  - name: PreProdEnvironment
    value: &quot;env-url&quot;
  - name: ProdEnvironment
    value: &quot;env-url&quot;

stages:
- stage: Build
  displayName: &#39;Build stage&#39;
  jobs:
  - job: Build
    displayName: &#39;Build job&#39;
    steps:
    - script: echo &#39;Building the Synapse Analytics workspace...&#39;
      displayName: &#39;Build step&#39;

- stage: DeployToDev
  displayName: &#39;Deploy to Development&#39;
  dependsOn: Build
  condition: eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;)
  jobs:
  - job: Deploy
    displayName: &#39;Deploy job&#39;
    steps:
    - task: AzureResourceGroupDeployment@2
      inputs:
        deploymentScope: &#39;Resource Group&#39;
        azureResourceManagerConnection: &#39;MyAzureResourceManagerConnection&#39;
        subscriptionId: &#39;&lt;subscription-id&gt;&#39;
        action: &#39;Create Or Update Resource Group&#39;
        resourceGroupName: &#39;&lt;resource-group-name&gt;&#39;
        location: &#39;&lt;resource-group-location&gt;&#39;
        templateLocation: &#39;Linked artifact&#39;
        csmFile: &#39;&lt;path-to-arm-template&gt;&#39;
        csmParametersFile: &#39;&lt;path-to-arm-template-parameters&gt;&#39;
        overrideParameters: &#39;-environment $(DevEnvironment)&#39;

- stage: DeployToTest
  displayName: &#39;Deploy to Test&#39;
  dependsOn: Build
  condition: and(eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;), eq(variables[&#39;Build.Reason&#39;], &#39;Schedule&#39;))
  jobs:
  - job: Deploy
    displayName: &#39;Deploy job&#39;
    steps:
    - task: AzureResourceGroupDeployment@2
      inputs:
        deploymentScope: &#39;Resource Group&#39;
        azureResourceManagerConnection: &#39;MyAzureResourceManagerConnection&#39;
        subscriptionId: &#39;&lt;subscription-id&gt;&#39;
        action: &#39;Create Or Update Resource Group&#39;
        resourceGroupName: &#39;&lt;resource-group-name&gt;&#39;
        location: &#39;&lt;resource-group-location&gt;&#39;
        templateLocation: &#39;Linked artifact&#39;
        csmFile: &#39;&lt;path-to-arm-template&gt;&#39;
        csmParametersFile: &#39;&lt;path-to-arm-template-parameters&gt;&#39;
        overrideParameters: &#39;-environment $(TestEnvironment)&#39;

- stage: DeployToPreProd
  displayName: &#39;Deploy to Pre-Production&#39;
  dependsOn: Build
  condition: and(eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;), eq(variables[&#39;Build.Reason&#39;], &#39;Manual&#39;))
  jobs:
  - job: Deploy
    displayName: &#39;Deploy job&#39;
    steps:
    - task: AzureResourceGroupDeployment@2
      inputs:
        deploymentScope: &#39;Resource Group&#39;
        azureResourceManagerConnection: &#39;MyAzureResourceManagerConnection&#39;
        subscriptionId: &#39;&lt;subscription-id&gt;&#39;
        action: &#39;Create Or Update Resource Group&#39;
        resourceGroupName: &#39;&lt;resource-group-name&gt;&#39;
        location: &#39;&lt;resource-group-location&gt;&#39;
        templateLocation: &#39;Linked artifact&#39;
        csmFile: &#39;&lt;path-to-arm-template&gt;&#39;
        csmParametersFile: &#39;&lt;path-to-arm-template-parameters&gt;&#39;
        overrideParameters: &#39;-environment $(PreProdEnvironment)&#39;

- stage: DeployToProd
  displayName: &#39;Deploy to Production&#39;
  dependsOn: Build
  condition: and(eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;), eq(variables[&#39;Build.Reason&#39;], &#39;Manual&#39;))
  jobs:
  - job: Deploy
    displayName: &#39;Deploy job&#39;

Approach 3)

Alternatively you can also configure different stages Dev, Test, Prod, Pre-Prod to deploy your Synapse workspace in specific environment like below:-

在 Azure Synapse Analytics 工作区中使用 DevOps 进行持续集成和交付

huangapple
  • 本文由 发表于 2023年2月18日 01:50:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定