【问题标题】:Execute simple SQL query though Azure Devops CICD pipeline通过 Azure Devops CI CD 管道执行简单的 SQL 查询
【发布时间】:2021-06-04 17:28:46
【问题描述】:

我是 Azure Devops 和 CICD 管道的新手。我的任务是创建一个 CICD 管道以从 Azure Devops CI/CD 管道执行 SQL 查询。我怎么做?任何建议都会有所帮助。

【问题讨论】:

  • 欢迎来到 Stack Overflow。以后,在提出问题时,请务必包括您尝试过的内容以及遇到的错误。虽然 @DreadedFrost 能够提供答案,但 Stack Overflow 更适合解决特定的技术问题,而不是一般的“入门”类型的问题。

标签: azure devops cicd


【解决方案1】:

SQL 查询可以通过ADO tasks 运行

类似:

variables:
  AzureSubscription: '<Azure service connection>'
  ServerName: '<Database server name>'
  DatabaseName: '<Database name>'
  AdminUser: '<SQL user name>'
  AdminPassword: '<SQL user password>'
  SQLFile: '<Location of SQL file in $(Build.SourcesDirectory)>'

steps:
- task: AzurePowerShell@2
  displayName: Azure PowerShell script: FilePath
  inputs:
    azureSubscription: '$(AzureSubscription)'
    ScriptPath: '$(Build.SourcesDirectory)\scripts\SetAzureFirewallRule.ps1'
    ScriptArguments: '$(ServerName)'
    azurePowerShellVersion: LatestVersion

- task: CmdLine@1
  displayName: Run Sqlcmd
  inputs:
    filename: Sqlcmd
    arguments: '-S $(ServerName) -U $(AdminUser) -P $(AdminPassword) -d $(DatabaseName) -i $(SQLFile)'

- task: AzurePowerShell@2
  displayName: Azure PowerShell script: FilePath
  inputs:
    azureSubscription: '$(AzureSubscription)'
    ScriptPath: '$(Build.SourcesDirectory)\scripts\RemoveAzureFirewallRule.ps1'
    ScriptArguments: '$(ServerName)'
    azurePowerShellVersion: LatestVersion

请注意,如果您使用防火墙规则,额外的步骤是删除防火墙

【讨论】:

  • 使用 AzurePowerShell@2 执行 SQL 查询,它工作正常。谢谢你的信息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-20
  • 2020-10-13
  • 2020-04-07
  • 2022-01-02
  • 2022-07-04
  • 2022-01-06
  • 2021-09-14
相关资源
最近更新 更多