我有以下提交完成时执行的提交后挂钩:
PostCommit.bat
@ECHO OFF
set local
set REPOS=%1
set REV=%2
set TXN_NAME=%3
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%emailer.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' 'REPOS' 'REV' TXN_NAME";
我正在尝试使用以下 powershell 脚本通过电子邮件发送存储库链接、修订号和事务。
emailer.ps1
function mailer($Repos,$Rev,$TXN_NAME)
{
$smtp = new-object Net.Mail.SmtpClient("webmail.companyname.com")
$objMailMessage = New-Object System.Net.Mail.MailMessage
$objMailMessage.From = "Automation@companyname.com"
$i = 0
Get-Content "X:\Department\Con\Hyd\Technical\TestPool\recepients.txt" | foreach {
$emailid = $_.split(";")
$emailid | foreach{
$objMailMessage.To.Add($emailid[$i])
$i++
}
}
$objMailMessage.Subject = "A commit operation has been performed! "
$objMailMessage.Body = "A commit operation has been performed at repository "+$Repos+" and the latest revision is "+$Rev
$smtp.send($objMailMessage)
}
提交更改后,我看不到任何错误消息,也不会收到任何电子邮件。我想问题出在通过命令行调用 powershell 脚本时。如果有人能建议如何在邮件中添加作者的名字,那也很棒。
提前致谢。