sql - 从 Azure SQL InlineSqlTask​​ 任务创建输出变量 azure devops

标签 sql azure azure-devops yaml

我在 yaml 中使用了 azure devops :

- task: SqlAzureDacpacDeployment@1
  displayName: 'Azure SQL InlineSqlTask'
  inputs:
    azureSubscription: 'Service Connection'
    AuthenticationType: servicePrincipal
    ServerName: 'xxx.database.windows.net'
    DatabaseName: 'xxx-Dev'
    deployType: InlineSqlTask
    SqlInline: |
     select name as username,
                  create_date,
                  modify_date,
                  type_desc,
                  authentication_type_desc as authentication_type
                  from sys.database_principals where type_desc = 'EXTERNAL_USER'

我需要能够获取存储在变量中的 t-sql 命令的输出,以便稍后在管道中使用它。任何想法如何获取此输出并将其存储在变量中。

我通常会使用 powershell 命令来设置环境变量,但显然这不能在此任务中完成。

任何想法都会很棒。

最佳答案

我已经解决了这个问题。因此,我可以在 Azure Devops 中使用 powershell 脚本,这样我就可以直接获取变量,然后使用 setvariable 任务将输出分配为 env:variable。

$query = "select name as username,
             create_date,
             modify_date,
             type_desc,
             authentication_type_desc as authentication_type
             from sys.database_principals where type_desc = 'EXTERNAL_USER'"

$clientid = "guid"
$tenantid = "guid"
$secret = "guid"

$request = Invoke-RestMethod -Method POST `
           -Uri "https://login.microsoftonline.com/$tenantid/oauth2/token"`
           -Body @{ resource="https://database.windows.net/"; grant_type="client_credentials"; client_id=$clientid; client_secret=$secret }`
           -ContentType "application/x-www-form-urlencoded"
$access_token = $request.access_token


$sqloutput = Invoke-Sqlcmd -ServerInstance $.database.windows.net -Database db$ -AccessToken $access_token -query $query


Write-Host "##vso[task.setvariable variable=GetVar;]$sqloutput"

关于sql - 从 Azure SQL InlineSqlTask​​ 任务创建输出变量 azure devops,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71680561/

相关文章:

sql select * 在精确的行数之间

sql - 使用带有分号字符的 STRPOS 时出现语法错误或访问冲突

php - 我如何修复子查询返回多于 1 行的错误

c# - 如何向 SonarQube 添加单元测试覆盖率?使用 Azure-DevOps 管道

SQL 将现有/重复的行插入表中但只更改一列值?

c# - 缺少将 Microsoft.IdentityModel.Clients.ActiveDirectory 3.13.9 与 Azure KeyVault C# SDK 结合使用的程序集引用

.net - 一个 Web 角色上的两个 Web 应用程序 - 配置问题

powershell - 检索 Azure 服务主体证书

azure-devops - CS0579 : Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute'

oauth - 使用服务连接获取 OAuth token