An attachment statement can only be included in a notify block. It is used to add an attachment into an outgoing email (via SMTP notifiers). It allows much finer control over the attachment content than that provided by the attachment parameter to the notify statement.


attachment takes a number of named parameters:


name

The name of the attachment. The attachment will appear with this name in the received email.

body

Optional. A stream. The content of the stream creates the content of the attachment.


attachment can optionally open a code block. If body is not specified then the content of the attachment is taken from the output created by this code block.


Example: Checkout a file and include it as an attachment in an email:


// Checkout "myfile.txt" and read it into the stream $myfile.

using DropZone "test" {

 checkout(repository: "Openmake_Demo.demorep2", pattern: "myfile.txt");

 using stream $myfile {

 read(file: "myfile.txt");

 }

}

// Send the email, including the attachment.

set me=me();

notify(notifier: "SMTP_Notifier", to: $me, subject: "Example 1") {

 echo "Dear ${me.realname}";

 echo "";

 echo "Attached is myfile.txt for your information";

 attachment(name: "myfile.txt", body: $myfile);

}


Example: Create an attachment with a script and include it in an email:


set me=me();

notify(notifier: "SMTP_Notifier", to: $me, subject: "Example 2") {

 echo "Dear ${me.realname}";

 echo "";

 echo "Attached is genfile.txt which is created by a script";

 attachment(name: "genfile.txt") {

    echo "These lines are included in genfile.txt";

    echo "The following lines are generated from an external script";

    testaction(arg1: 'hello', arg2: 'world');

 }

}


Example: Send an email containing the Change Requests associated with the Application.


set me=me();

set crlist = ${Application.requests};

notify(notifier: 'SMTP_Notifier',to: $me, subject: 'Test Notification', HTML: true) {

 echo "<h3>Dear ${me.realname}</h3>";

 echo "Change Requests for Application ${Application.name}";

 echo "<table border=1>";

 iterate(cr: $crlist) {

   echo "<tr><td>${cr.id}</td><td>${cr.name}</td></tr>";

 }

 echo "</table>";

}


Email Received:


Dear John Doe


Change Requests for Application ITGuys;3


140

Need to Have Creation Rights to Build Engines, Just Like Other Objects

TS-8

As a product owner, I'd like to include bugs, tasks and other issue types in my backlog >> Bugs like this one will also appear

145

Saving a field including a % char in the action editor clears the field

TS-5

As a team, I'd like to commit to a set of stories to be completed in a sprint (or iteration) >> Click "Create Sprint" then drag

TS-1

As an Agile team, I'd like to learn about Scrum >> Click the "TS-1" link at the left of this row to see detail in the Description.