SVN龟中的postcommit.bat脚本钩子

时间:2014-05-03 04:19:09

标签: svn powershell tortoisesvn post-commit post-commit-hook

我有以下postcommit挂钩,在提交完成后执行:

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

提前致谢。

1 个答案:

答案 0 :(得分: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不是很熟悉;所以不太了解获得作者的名字。

相关问题