在下一步中获取任务状态 [英] Get task status in next step

查看:58
本文介绍了在下一步中获取任务状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行测试的任务 Maven @ 3 ,我想在下一个任务中获取其状态.有变数吗?

I have a task Maven@3 that is running my tests and I would like to get its status in a next task. Is there a variable to get it ?

例如:

  - task: Maven@3
    displayName: UnitTest
    name: UnitTest
    inputs:
      ...maven options...
      goals: 'test'
  - script: echo $(succeeded('UnitTest'))

在脚本步骤中,我想打印UnitTest Task的状态.

In the script steps, I would like to print the UnitTest Task status.

推荐答案

解决方法是使用多作业管道来将UnitTest任务与单独的作业以及其他依赖于该作业的作业分开.然后,您可以使用表达式 $ [dependency.A.result] 来获取UnitTest状态.请检查以下示例:

The workaround is to use multi job pipeline to separate UnitTest task in a separate job and other jobs dependent on it. Then you can use expression $[ dependencies.A.result ] to get the UnitTest status. Please check below example:

jobs:

- job: A
  pool: 
    vmImage: windows-latest
  steps:
    - checkout: none  #use checkout step to void syncing repo

    - task: Maven@3

- job: B 
  dependsOn: A
  condition: always()
  variables:
    testStatus: $[ dependencies.A.result ]
  steps:
    - script: echo $(testStatus) 

您还可以提交功能请求(点击建议功能"并选择Azure devops)作为支持变量,以将任务状态获取给Microsoft开发团队.

You can also submit a feature request(Click a suggest a feature and choose Azure devops) for supporting variable to get Task status to Microsoft Development team.

更新:

使用Azure devops rest api获取任务状态.下面是脚本:

Use Azure devops rest api to get Task status. Below is the scripts:

- powershell: |  
    $url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/timeline?api-version=5.1"

    $result = Invoke-RestMethod -Uri $url -Headers @{authorization = "Bearer $(system.accesstoken)"} -ContentType "application/json" -Method get

    $taskResult = $result.records | where {$_.name -eq "UnitTest"} | select result

    echo $taskResult 
  condition: always()

这篇关于在下一步中获取任务状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆