1

我有以下提交完成时执行的提交后挂钩:

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 脚本时。如果有人能建议如何在邮件中添加作者的名字,那也很棒。

提前致谢。

4

1 回答 1

1

mailer您在emailer.ps1文件中有一个函数。

但是,您不会mailer在脚本内的任何地方调用该函数。这可能是您没有收到电子邮件的原因。

因此,您需要更改脚本emailer.ps1

例如:

param(
        [Parameter(Position=0, Mandatory=$true)]
        [string] $Repos,
        [Parameter(Position=1, Mandatory=$true)]
        [string]$Rev,
        [Parameter(Position=2, Mandatory=$true)]
        [string]$TXN_NAME
    )
$smtp = new-object Net.Mail.SmtpClient("webmail.factset.com")
$objMailMessage = New-Object System.Net.Mail.MailMessage
$objMailMessage.From = "FFTO-Automation@factset.com"
$i = 0 
Get-Content "H:\Department\Content\Hyderabad\FF_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)

我对乌龟svn不是很熟悉;所以不太了解获取作者的名字。

于 2014-05-03T05:55:43.697 回答