15

I am trying in a pipeline to attach files to my notification mails.

How can I do that? An example would be nice.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
eran meiri
  • 1,322
  • 3
  • 12
  • 29

1 Answers1

33

email-ext uses Ant File Syntax

As for example usage:

emailext attachmentsPattern: '**/report.html', body: 'Find attachments', subject: 'test', to: 'test@me.org'
hakamairi
  • 4,464
  • 4
  • 30
  • 53
  • 2
    attachementPattern does not accept all file path ?? for example ${workspace}/file.xml – sirineBEJI Jul 05 '18 at 09:20
  • 1
    works as expected. another thing that is important in this context, is another boolean key/value 'attachLog: true' . not to be confused (as i did...) - the boolean is only for sending the build log of jenkins itself, rather than 'attachmentsPattern' which allow to customize based on Ant patterns – chenchuk Jun 14 '19 at 06:51
  • 1
    def file_name = "file.txt" and calling `attachmentsPattern: "${file_name}"`. its unable to call that file. please suggest – Suraj Nerati Dec 18 '19 at 04:42
  • if there are two files then? – User Apr 23 '21 at 18:14
  • Hi @Khan, would you be able to write a pattern that matches both of them? – hakamairi Apr 24 '21 at 10:46
  • For example the all files in a folder reports, so can I do like `**/reports/*` – User Apr 24 '21 at 10:51
  • The first start should be doubled unless you can provide a full path (then it matches all report directories in your working directory tree). Then you need a star at the end to pick all the files in the matched directories. EDIT: yeah, just like you edited. – hakamairi Apr 24 '21 at 10:55
  • 2
    Also you can add specific more than one file: attachmentsPattern: 'report.html, test.html,....' – Yakir GIladi Edry May 20 '21 at 08:16
  • I am getting ERROR: Error accessing files to attach: Expecting Ant GLOB pattern, but saw '/tmp/output.text' ...... I want to attach file /tmp/output.text – Ashish Karpe Jan 05 '23 at 11:14
  • @AshishKarpe this pattern is relative to your workspace, you would need to do ../ as many times to get to the /, and then have the rest of it, for example ../../../../tmp/output.text – hakamairi Jan 05 '23 at 12:40
  • @hakamairi I tried to cp /tmp/output.text $WORKSPACE/ but my workspace is getting cleaned so getting error – Ashish Karpe Jan 06 '23 at 03:08