2017-05-04 7 views
0

Ich habe Oktopus Variablen unter „Library“ -> „Variable Sets“ Variablen mit NamenOctopus Ausgangsgrößen und den Zugriff auf sie

1. DatabaseExceptions 
2. ReportsExceptions 
3. ApplicationExceptions 

Und ich habe Setup meines Projekts „Deployment-Prozess“ in Krake als Schritte

1. Database 
2. Reports 
3. Application 
4. Send Email 

die obige Variable sind mit Ausnahmen unter Verwendung von ‚Power‘ Skripte gesetzt, die auf Ausnahmen in Skripten predeploy.ps1 des bestimmten Schritt aufgerufen werden.

Im letzten Schritt (E-Mail senden) habe ich versucht, eine E-Mail mit den Informationen in Ausnahmevariablen zu senden, indem überprüft wird, ob eine bestimmte Variable Informationen enthält.

ich dies in der E-Mail schicken Schritt Körper mache, indem Sie das Kontrollkästchen Überprüfung („Body als HTML“)

<h2>Deployment Steps</h2> 
<ol> 
    #{each step in Octopus.Step} 
     #{if step.Status.Code} 
      <li>#{step | HtmlEscape} &mdash; 
       #{if Step.Name == "Database"} 
        #{if Octopus.Action[Database].Output.DatabaseExceptions} 
         <pre>#{Octopus.Action[Database].Output.DatabaseExceptions}</pre> 
        #{/if} 
       #{/if} 
       #{if Step.Name == "Reports"} 
        #{if Octopus.Action[Reports].Output.ReportsExceptions} 
         <pre>#{Octopus.Action[Reports].Output.ReportsExceptions}</pre> 
        #{/if} 
       #{/if} 
       #{if Step.Name == "Application"} 
        #{if Octopus.Action[Application].Output.ApplicationExceptions} 
         <pre>#{Octopus.Action[Application].Output.ApplicationExceptions}</pre> 
        #{/if} 
       #{/if} 
      </li> 
     #{/if} 
    #{/each} 
</ol> 

Die Datenbank und Berichte Skripte hat Fehler und meine Ausgabe sieht wie folgt unter dem korrekt ist wie

erwartet
Deployment Steps 
1. Database — Exception on processing DB scripts - info:... 
2. Reports — Exception on processing Reports - info:... 
3. Application 
4. Send Email 

Und meine Frage:

Ist es möglich, etwas wie unten als mein Schritt Name und Start meiner Variablennamen sind die gleichen

<h2>Deployment Steps</h2> 
<ol> 
    #{each step in Octopus.Step} 
     #{if step.Status.Code} 
      <li>#{step | HtmlEscape} &mdash; 
        #{if Octopus.Action[#{step.Name}].Output.#{step.Name}Exceptions} 
         <pre>#{Octopus.Action[#{step.Name}].Output.#{step.Name}Exceptions}</pre> 
        #{/if} 
      </li> 
     #{/if} 
    #{/each} 
</ol> 

Antwort

1

Leider, das nicht zu sein scheint möglich innerhalb der E-Mail-Vorlage zu tun. Siehe this thread in Octopus-Unterstützung.

auch nur zu beachten, können Sie die gleiche Leistung in jedem Schritt Variablennamen erforderlich verwenden könnte, und es wäre für jeden Schritt einen anderen Bereich, dh

Set-OctopusVariable -name "Exceptions" -value $someValue 

Und möglicherweise könnte die Lösung einen separaten zu haben sein Script-Schritt zur Vorbereitung der exceptions für den E-Mail-Schritt. Etwas wie:

$exceptions = "" 
$OctopusParameters.GetEnumerator() | Where-Object { $_.Key -like '*Output.Exceptions*' } | % { 
    Write-Host " $($_.Key) - $($_.Value)" 
    $exceptions += $_.Value + "`r`n" 
} 

Set-OctopusVariable -name "ExceptionsToEmail" -value $exceptions 

Und dann könnte man die Variable in dem E-Mail-Schritt, ohne die Notwendigkeit einer Schleife durch die Schritte verwenden:

<pre> 
    Exceptions: 
    #{Octopus.Action[Prep Email Output].Output.ExceptionsToEmail} 
</pre> 

aktualisiert Lösung

Wie oben erwähnt, wenn man Derselbe Name der Ausgangsvariablen wurde unter den Schritten geteilt, dann könnte die Lösung vereinfacht werden, ohne dass ein separater Skriptschritt erforderlich wäre. Alle würden in der E-Mail-Vorlage erfolgen:

#{each action in Octopus.Action} 
    <strong>#{action.Name}</strong> 
    #{if action.Output.Exceptions} 
     <p> - #{action.Output.Exceptions}</p> 
    #{/if} 
    #{unless action.Output.Exceptions} 
     - Succeeded 
    #{/unless} 
#{/each} 

, die in einer E-Mail-Ausgabe wie führen würden:

Database - database exception occured 
Reports - reports exception occured 
Application - some application exception occurred 
Some other step - Succeeded 
Send email - Succeeded 
+0

Hallo Alex, ich bin wirklich traurig über die späte Antwort. Ich weiß Ihre Antwort sehr zu schätzen, was mir bei der Änderung meiner E-Mail-Benachrichtigung hilfreich ist. Nochmals vielen Dank für die Lösung. –

Verwandte Themen