Domanda

I have the following postcommit hook that executes when a commit is done:

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";

I'm trying to send the repository link, Revision # and transaction via e-mail using the below powershell script.

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)
}

Once I commit my changes, I don't see any error messages nor receive any e-mails. I guess the problem is while calling the powershell script via commandline. Also it would be great if anybody could suggest how to add the author's name in the mail.

Thanks in advance.

È stato utile?

Soluzione

You have a function mailer in the emailer.ps1 file.

But, you are not calling the function mailer anywhere inside the script. That could be the reason why you are not receiving the email.

So, you would need to change the script emailer.ps1:

For example:

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)

I am not very familiar with tortoise svn; so do not know much about getting the author's name.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top