如何将 TeamCity 故障条件中的值传递给电子邮件通知?
How can I pass a value from a TeamCity failure Condition to an e-mail notification?
我想在电子邮件中显示构建状态,正文中只显示简单的失败或通过文本。似乎没有任何我可以在 TeamCity 中访问或设置的预定义“buildStatus”变量。我想我需要访问底部的“failureConditions”函数但不确定如何尝试很多东西但没有任何效果,这是我的脚本:
package _Self.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.BuildFailureOnText
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.failOnText
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule
allowExternalStatus = true
params {
param("MinorVersion", "0")
param("RevisionVersion", "0")
}
powerShell {
name = "Email"
scriptMode = script {
content = """
function Send-ToEmail([string]${'$'}email, [string]${'$'}attachmentpath){
${'$'}message = new-object Net.Mail.MailMessage;
${'$'}message.From = "teamcity@blog.com";
${'$'}message.To.Add(${'$'}email);
${'$'}message.Subject = "%env.TEAMCITY_PROJECT_NAME% | %VersionNumber% ";
${'$'}message.Body = "The build: PASS or FAIL text here";
${'$'}smtp = new-object Net.Mail.SmtpClient("blog.local", "25");
${'$'}smtp.EnableSSL = ${'$'}true;
${'$'}smtp.send(${'$'}message);
write-host "Mail Sent" ;
}
Send-ToEmail -email "me@blog.com" -attachmentpath ${'$'}path;
""".trimIndent()
}
}
}
failureConditions {
failOnText {
conditionType = BuildFailureOnText.ConditionType.CONTAINS
pattern = "FAIL"
reverse = false
}
}
在T/C中解决这个问题:
- 创建新的自定义环境。变种。例如
MyBuildStatus
- 创建新的构建步骤,例如
Set build status
(仅在构建成功时执行)
- 新建参数名称='env.MyBuildStatus.Status'值='SUCCESS'
- 向电子邮件主题添加变量:$message.Subject = "%env.MyBuildStatus.Status%
为什么 T/C 在“buildstatus”环境中没有构建。变量很有趣。
我想在电子邮件中显示构建状态,正文中只显示简单的失败或通过文本。似乎没有任何我可以在 TeamCity 中访问或设置的预定义“buildStatus”变量。我想我需要访问底部的“failureConditions”函数但不确定如何尝试很多东西但没有任何效果,这是我的脚本:
package _Self.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.BuildFailureOnText
import jetbrains.buildServer.configs.kotlin.v2019_2.failureConditions.failOnText
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule
allowExternalStatus = true
params {
param("MinorVersion", "0")
param("RevisionVersion", "0")
}
powerShell {
name = "Email"
scriptMode = script {
content = """
function Send-ToEmail([string]${'$'}email, [string]${'$'}attachmentpath){
${'$'}message = new-object Net.Mail.MailMessage;
${'$'}message.From = "teamcity@blog.com";
${'$'}message.To.Add(${'$'}email);
${'$'}message.Subject = "%env.TEAMCITY_PROJECT_NAME% | %VersionNumber% ";
${'$'}message.Body = "The build: PASS or FAIL text here";
${'$'}smtp = new-object Net.Mail.SmtpClient("blog.local", "25");
${'$'}smtp.EnableSSL = ${'$'}true;
${'$'}smtp.send(${'$'}message);
write-host "Mail Sent" ;
}
Send-ToEmail -email "me@blog.com" -attachmentpath ${'$'}path;
""".trimIndent()
}
}
}
failureConditions {
failOnText {
conditionType = BuildFailureOnText.ConditionType.CONTAINS
pattern = "FAIL"
reverse = false
}
}
在T/C中解决这个问题:
- 创建新的自定义环境。变种。例如
MyBuildStatus
- 创建新的构建步骤,例如
Set build status
(仅在构建成功时执行) - 新建参数名称='env.MyBuildStatus.Status'值='SUCCESS'
- 向电子邮件主题添加变量:$message.Subject = "%env.MyBuildStatus.Status%
为什么 T/C 在“buildstatus”环境中没有构建。变量很有趣。