在Azure任务上设置变量,以通过Azure Pipeline的另一个任务

发布于 2025-01-23 11:17:05 字数 895 浏览 0 评论 0原文

我能够在PowerShell或Bash脚本上设置一个变量,并通过使用## VSO [task.set.setVariable actible = abc;] xyz将变量传递给另一个任务。但是找不到任何文档可以在Azure任务上设置变量,例如Azure WebApp部署任务或sqlazuredacpacdeployment任务。我想通过传递变量值来捕获错误。有没有有效的方法来捕获下一个任务的Azure任务错误日志?

- task: SqlAzureDacpacDeployment@1
  displayName: 'Insertion SQL Task'
  inputs:
    azureSubscription: 'Org (xxxxx-xxxx-xxxx-xxxx-xxxx)'
    ServerName: 'tcp:abc.database.windows.net'
    DatabaseName: test_db
    SqlUsername: '$(user)'
    SqlPassword: $(pass)
    deployType: SqlTask
    SqlFile: 'SQL/test.sql'
  enabled: true

- task: AzureWebApp@1
  displayName: 'Azure Web App Deploy: $(AppName)'
  inputs:
    azureSubscription: 'Org (xxxxx-xxxx-xxxx-xxxx-xxxx)'
    appType: webApp
    ResourceGroupName: 'Test'
    appName: '$(AppName)'
    package: '$(Build.ArtifactStagingDirectory)\app/*.zip'
    deploymentMethod: zipDeploy
  enabled: true

I am able to set a variable on powershell or bash script and pass the variable to another task by using ##vso[task.setvariable variable=abc;]xyz. But couldn't find any documentation to set variable on azure tasks like azure webapp deploy task or SqlAzureDacpacDeployment task. I want to catch the error by passing the variable value. Is there any effective way to catch the azure task error log for the next task?

- task: SqlAzureDacpacDeployment@1
  displayName: 'Insertion SQL Task'
  inputs:
    azureSubscription: 'Org (xxxxx-xxxx-xxxx-xxxx-xxxx)'
    ServerName: 'tcp:abc.database.windows.net'
    DatabaseName: test_db
    SqlUsername: '$(user)'
    SqlPassword: $(pass)
    deployType: SqlTask
    SqlFile: 'SQL/test.sql'
  enabled: true

- task: AzureWebApp@1
  displayName: 'Azure Web App Deploy: $(AppName)'
  inputs:
    azureSubscription: 'Org (xxxxx-xxxx-xxxx-xxxx-xxxx)'
    appType: webApp
    ResourceGroupName: 'Test'
    appName: '$(AppName)'
    package: '$(Build.ArtifactStagingDirectory)\app/*.zip'
    deploymentMethod: zipDeploy
  enabled: true

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一生独一 2025-01-30 11:17:05

您需要为任务设置名称。

对于 Azure SQL数据库部署任务,您可以使用sqldeploymentOutputfile输出变量名称。

- task: SqlAzureDacpacDeployment@1
  displayName: 'Insertion SQL Task'
  name: sqlInsert
  inputs:
    ...
  enabled: true

- script: echo "$(sqlInsert.SqlDeploymentOutputFile)"

Azure Web应用程序任务不提供相同的机制。您总是可以致电管道 - 获取日志api 以获取所需的东西:

pool:
  vmImage: ubuntu-latest

steps:
- powershell: Write-Host "Hello World"
  name: 'HelloWorld'

- powershell: |
    Write-Host "This is a script that could use $env:SYSTEM_ACCESSTOKEN"
    
    # Construct the REST URL to obtain Build ID
    $uri = "$(System.CollectionUri)$(System.TeamProject)/_apis/pipelines/$(System.DefinitionId)/runs/$(Build.BuildId)/logs?api-version=6.0-preview.1"
    Write-Host "$uri"

    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "system", $env:SYSTEM_ACCESSTOKEN)))
    $logs = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

You will need to set a name for the task.

For Azure SQL Database Deployment task, you can use the SqlDeploymentOutputFile output variable name.

enter image description here

- task: SqlAzureDacpacDeployment@1
  displayName: 'Insertion SQL Task'
  name: sqlInsert
  inputs:
    ...
  enabled: true

- script: echo "$(sqlInsert.SqlDeploymentOutputFile)"

The Azure Web App task does not provide the same mechanism. You could always call the Pipelines - Get Logs API to get what you need:

pool:
  vmImage: ubuntu-latest

steps:
- powershell: Write-Host "Hello World"
  name: 'HelloWorld'

- powershell: |
    Write-Host "This is a script that could use $env:SYSTEM_ACCESSTOKEN"
    
    # Construct the REST URL to obtain Build ID
    $uri = "$(System.CollectionUri)$(System.TeamProject)/_apis/pipelines/$(System.DefinitionId)/runs/$(Build.BuildId)/logs?api-version=6.0-preview.1"
    Write-Host "$uri"

    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "system", $env:SYSTEM_ACCESSTOKEN)))
    $logs = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文