【问题标题】:postcommit.bat script hook in SVN tortoiseSVN 乌龟中的 postcommit.bat 脚本挂钩
【发布时间】:2014-05-03 04:19:08
【问题描述】:

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

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

提前致谢。

【问题讨论】:

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


    【解决方案1】:

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

    但是,您没有在脚本内的任何地方调用函数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)
    

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

    【讨论】:

    • 当您使用它时,升级脚本以使用Send-MailmessageNet.Mail.SmtpClient 仅在 PowerShell v1 中需要,Send-MailMessage 更简洁。
    • 非常感谢!会做! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    相关资源
    最近更新 更多