是否可以将 Curl 命令结果发送到 Azure DevOps 内置通知电子邮件

Can I send Curl command result to a Azure DevOps built-in notification email

提问人:eliew 提问时间:11/16/2023 更新时间:11/16/2023 访问量:40

问:

我有一个运行一些简单 Curl 命令的管道“http_status1=$(curl -s -o /dev/null -w ”%{http_code}“ URL)” 。这将仅在 http_status1(200、401 等)中保存状态,而不是返回整个卷曲,并且工作正常。我的一位潜在客户还设置了警报通知电子邮件,每次管道在失败或成功时都会触发该电子邮件,这也很好。我的问题是,有没有办法在我的管道脚本中添加代码或命令,在电子邮件中包含http_status1的值?我无权访问通知设置,因此我无法在那里执行任何操作来修改电子邮件内容/正文。我的任务是带有内联脚本的bash@3

提前致谢

bash azure-devops azure-pipelines

评论

0赞 xpusostomos 11/17/2023
这与 bash 标签几乎没有关系

答:

0赞 Bright Ran-MSFT 11/16/2023 #1

Azure Pipelines 中没有内置任务或功能可以将任务输出作为电子邮件通知发送。

但是,在Azure DevOps的市场中,可以找到一些扩展,这些扩展提供用于发送电子邮件管道任务。

注意:几乎所有发送电子邮件任务都需要您提供 SMTP 服务器的设置。这意味着您需要配置一个 SMTP 服务器以用于发送电子邮件任务。


对于您的情况,下面是一个示例作为参考:

steps:
# Get the HTTP Status and set it as a pipeline variable.
- task: Bash@3
  displayName: 'Get HTTP Status'
  inputs:
    targetType: inline
    script: |
      http_status1=$(curl -s -o /dev/null -w "%{http_code}" URL)
      echo "##vso[task.setvariable variable=HTTP_STATUS1;]$http_status1"

# Send the HTTP Status via email.
- task: SendEmail@1
  displayName: 'Send HTTP Status'
  inputs:
    To: '{email addresses to receive the message}'
    From: '{email address to send the message}'
    Subject: 'HTTP Status'
    Body: |
     Successfully get the HTTP Status.
     The HTTP Status is: $(HTTP_STATUS1).
    SmtpServer: '$(Mail.Server)'
    SmtpPort: '$(Mail.Port)'
    SmtpUsername: '$(Mail.Username)'
    SmtpPassword: '$(Mail.Password)'

评论

0赞 eliew 11/16/2023
感谢您的帮助!不幸的是,我们不能在我的项目中使用 SMTP 服务器。对不起,这是我应该提到的。我会继续在市场上寻找一些可能不需要 SMTP 的扩展。
0赞 Bright Ran-MSFT 11/17/2023
@eliew,不客气。到目前为止,在管道中使用发送电子邮件任务可能是我能想到的用例的唯一可用方法。当然,您可以在市场上进一步搜索,看看是否有任何扩展不需要您提供 SMTP 服务器配置。