2017-05-15 34 views
-1

特定の電子メールを所定のユーザーに送信し、Outlookを使用し、Outlookが同じマシン(Windowsプラットフォーム上)で実行されるのを待ちます。JenkinsはOutlookでPowerShellスクリプトを使用して電子メールを送信できません

Jenkinsでは、このPowerShellスクリプトファイルとバッチファイル(PowerShellファイルが組み込まれている)を使ってこのメールを送信してみました。

最初に私はエラーThe remote procedure call failedに遭遇しましたが、何とかそれはなくなってしまい、電子メールを送信しません。 cmdまたはPowerShellターミナルを使用すると、完璧に動作します。 のような私のコード:

# Filters and zips the files before sending by email 
Function PreProcessAttachments 
{ 
[cmdletBinding()] 
param(
    [Parameter(Mandatory=$true)] [string]$integrationOutputFilePath, 
    [Parameter(Mandatory=$true)] [string]$updateLogFilePath) 

$attachments = @() 
if (Test-Path $integrationOutputFilePath) 
{ 
    $attachments += $integrationOutputFilePath 
} 
else 
{ 
    Write-Verbose ("Attachment file $integrationOutputFilePath " + 
     "does not exist. Ignoring.."); 
} 

if (Test-Path $updateLogFilePath) 
{ 
    $attachments += $updateLogFilePath 
} 
else 
{ 
    Write-Verbose ("Attachment file $integrationOutputFilePath " + 
     "does not exist. Ignoring.."); 
} 

return $attachments 
} 

Function ReportError 
{ 
[cmdletBinding()] 
param(
    [Parameter(Mandatory=$true)] [string]$stream, 
    [Parameter(Mandatory=$true)] [string]$integrationOutputFilePath, 
    [Parameter(Mandatory=$true)] [string]$updateLogFilePath) 


$attachments = PreProcessAttachments $integrationOutputFilePath 
        $updateLogFilePath; 

$subject = "[Integration Internal Error] at $stream" 

$body = "An internal error has occurred during integration.`n"; 
$body += "`nIntegration Log is attached to this e-mail.`n" 

$recipients = "[email protected]" 

write-output "Sending integration internal error email to: $recipients" 
try 
{ 
    SendEmailUsingOutLook $subject $recipients $body $attachments | Out-Null         
} 
catch 
{ 
    Write-Warning "Couldn't send integration internal error emails $_" 
} 
} 

# send e-mail using OutLook 
# note: Attachments should be an array: 
Function SendEmailUsingOutLook 
{ 
[cmdletBinding()] 
Param(
    [Parameter(Mandatory=$true)] [string]$subject, 
    [Parameter(Mandatory=$true)] [string]$to, 
    [Parameter(Mandatory=$true)] [string]$body, 
    $attachments) 

$Outlook = New-Object -ComObject Outlook.Application 
$Mail = $Outlook.CreateItem(0) 
$Mail.To = $to 
$Mail.Subject = $subject 
$Mail.Body = $body 

if ($attachments) 
{ 
    foreach ($file in $attachments) 
    { 
     $Mail.Attachments.Add($file)  
    } 
} 

$Mail.Send() 
} 

Function StartPocess 
{ 
$confFile = "path\to\myconf.xml" 
LoadConfs $confFile 

ReportError -stream $stream 
     -integrationOutputFilePath $integrationOutputFilePath 
     -updateLogFilePath $updateLogFilePath 
} 

# Start the script: 
StartPocess; 
+2

実装方法は?あなたのスクリプトは何ですか?どのようにそれを実行するのですか?いくつかのコードを表示するので、私たちは何か話をします。 – restless1987

+1

私は問題がコードではないと思った、それはジェンキンスやウィンドウのパーミッションについての何かだと思った[最小、完全で、かつ、検証可能な例](http://stackoverflow.com/help/mcve) – Clijsters

+0

を追加してください。とにかくコードを追加したものは何でも。 – tolgayilmaz

答えて

0

[OK]を問題は、(それが私の資格情報を使用して使用していたにも関わらず)、およびサービスは、私が思うPowerShellでcomobjectsに問題がある、私のジェンキンスがサービスとして実行されていたということでした。

  1. 私はjenkins.exe stop
  2. {JENKINS_HOME}\jre\bin\java -jar jenkins.war

また、これは私の空のジェンキンスインタフェースを示したが、私は新しいインストールフォルダに私の昔の仕事とpluginsディレクトリにコピーしたを使用してそれを開始し、コマンドラインusigからジェンキンスを停止{USERNAME}\.jenkinsの下にあり、samewayで再開されます。サービスは実行されておらず、Jenkinsはコマンドラインから作業しています。

関連する問題