@@ -112,7 +112,8 @@ class Pipeline extends DataObject {
112112 private static $ db = array (
113113 'Status ' => 'Enum("Running,Complete,Failed,Aborted,Rollback,Queued","Queued") ' ,
114114 'Config ' => 'Text ' , // serialized array of configuration for this pipeline
115- 'SHA ' => 'Varchar(255) '
115+ 'SHA ' => 'Varchar(255) ' ,
116+ 'LastMessageSent ' => 'Varchar(255) ' // ID of last message sent
116117 );
117118
118119 /**
@@ -205,10 +206,12 @@ public function getReplacements() {
205206 $ environment = $ this ->Environment ();
206207 return array (
207208 '<abortlink> ' => Director::absoluteURL ($ this ->Environment ()->Link ()),
209+ '<pipelinelink> ' => Director::absoluteURL ($ this ->Link ()),
208210 '<requester> ' => $ author ->Title ,
209211 '<requester-email> ' => $ author ->Email ,
210212 '<environment> ' => $ environment ->Name ,
211- '<project> ' => $ environment ->Project ()->Name
213+ '<project> ' => $ environment ->Project ()->Name ,
214+ '<commitsha> ' => $ this ->SHA
212215 );
213216 }
214217
@@ -539,7 +542,10 @@ public function markComplete() {
539542 $ this ->Status = "Complete " ;
540543 $ this ->log ("Pipeline completed successfully. " );
541544 $ this ->write ();
542- $ this ->sendMessage (self ::ALERT_SUCCESS );
545+ // Some steps may pre-emptively send a success message before the pipeline itself has completed
546+ if ($ this ->LastMessageSent !== self ::ALERT_SUCCESS ) {
547+ $ this ->sendMessage (self ::ALERT_SUCCESS );
548+ }
543549 }
544550
545551 /**
@@ -652,8 +658,10 @@ protected function canStartRollback() {
652658 * Notify Pipeline that a step has failed and failure processing should kick in. If rollback steps are present
653659 * the pipeline will be put into 'Rollback' state. After rollback is complete, regardless of the rollback result,
654660 * the pipeline will be failed.
661+ *
662+ * @param bool $notify Set to false to disable notifications for this failure
655663 */
656- public function markFailed () {
664+ public function markFailed ($ notify = true ) {
657665 // Abort all running or queued steps.
658666 $ steps = $ this ->Steps ();
659667 foreach ($ steps as $ step ) {
@@ -669,7 +677,7 @@ public function markFailed() {
669677 $ this ->Status = 'Failed ' ;
670678 $ this ->log ("Pipeline failed, not running rollback (not configured or not applicable yet). " );
671679 $ this ->write ();
672- $ this ->sendMessage (self ::ALERT_FAILURE );
680+ if ( $ notify ) $ this ->sendMessage (self ::ALERT_FAILURE );
673681 }
674682 }
675683
@@ -754,16 +762,22 @@ public function injectMessageReplacements($message, $subject, $substitutions) {
754762 /**
755763 * Sends a specific message to all marked recipients, including the author of this pipeline
756764 *
757- * @param string $messageID Message ID. One of 'Abort', 'Success', or 'Failure'
765+ * @param string $messageID Message ID. One of 'Abort', 'Success', or 'Failure', or some custom message
758766 * @return boolean True if successful
759767 */
760- protected function sendMessage ($ messageID ) {
768+ public function sendMessage ($ messageID ) {
761769 // Check message, subject, and additional arguments to include
762770 list ($ subject , $ message ) = $ this ->generateMessageTemplate ($ messageID );
763771 if (empty ($ subject ) || empty ($ message )) {
764772 $ this ->log ("Skipping sending message. None configured for $ messageID " );
765773 return true ;
766774 }
775+
776+ // Save last sent message
777+ $ this ->LastMessageSent = $ messageID ;
778+ $ this ->write ();
779+
780+ // Setup messaging arguments
767781 $ arguments = array_merge (
768782 $ this ->getConfigSetting ('PipelineConfig ' , 'ServiceArguments ' ) ?: array (),
769783 array ('subject ' => $ subject )
0 commit comments