Azure DevOps 通知 - 当电子邮件在一种状态下停留时间过长时就会发送

问题描述 投票:0回答:1

我想设置一个通知,如果某个项目在某一特定状态下停留时间过长(超过 2 天),则会发送电子邮件。我如何在通知功能中做到这一点?

我尝试设置它,但不确定使用什么公式来表示该天数。

azure-devops notifications
1个回答
0
投票

我想设置一个通知,如果某个项目在某一特定状态下停留时间过长(超过 2 天),则会发送电子邮件。我如何在通知功能中做到这一点?

恐怕目前还没有现成的方法可以实现这一点。通知仅监控工作项目

change

mostly nearby way
是检查这些工作项是否有
any changes
(不仅仅是状态变化),在DevOps管道中发送这些工作项的电子邮件通知。

详情如下:

  1. 我们可以尝试列出查询中的工作项,如下所示以进行检查。 列出

    user story
    状态为
    New
    ,并且在我这边 2 天内没有任何变化:

  2. 我们可以使用rest api Wiql - Query By Wiql 来实现相同的目的。

  3. 因此,在 DevOps 管道中,我们可以使用计划触发器运行管道

    every 2 days
    ,通过电子邮件发送这些工作项:

Yaml 示例如下:

trigger: none

schedules:
- cron: "0 0 */2 * *"
  displayName: Run every two days
  branches:
    include:
    - main

pool:
  vmImage: Windows-latest

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Define your organization, project, and personal access token
      $organization = "orgname"
      $project = "projectname"
      $pat = "$(pat)"
  
      # Define the date 2 days ago
      $date = (Get-Date).AddDays(-2).ToString('yyyy-MM-dd')
  
  
      # Define the API endpoint
      $url = "https://dev.azure.com/$organization/$project/_apis/wit/wiql?api-version=6.0"

  
      # Define the query
      $query = @{
          query = "SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = '$project' AND [System.WorkItemType] = 'User Story' AND [System.ChangedDate] < '$date' AND [System.State] = 'New'"
      } | ConvertTo-Json
  
      # Convert the PAT to a Base64 string
      $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
  
      # Make the API request
      $response = Invoke-RestMethod -Uri $url -Method Post -Body $query -ContentType "application/json" -Headers @{Authorization="Basic $base64AuthInfo"}

      # Output the response
      $response.workItems.id

      # Get the work item IDs
      $workItemIDs = $response.workItems.id

      # Convert the work item IDs to a string
      $workItemIDString = $workItemIDs -join ", "

      Write-Host "##vso[task.setvariable variable=WITlist;]$workItemIDString"

- task: SendEmail@1
  inputs:
    To: '[email protected]'
    From: '[email protected]'
    Subject: 'The work item not changed in 2 days'
    Body: |
      This is the work items not changed in 2 days for "New" state "User stories": 
      $(WITlist)
    BodyAsHtml: false
    AddAttachment: false
    SmtpServer: 'smtp-mail.outlook.com'
    SmtpUsername: '[email protected]'
    SmtpPassword: '$(pwd)'

我可以收到工作项目清单:

© www.soinside.com 2019 - 2024. All rights reserved.