Attach a file at custom location in mail from jenkins
To attach a file at a custom location in a mail sent from Jenkins, you can use the attachements
section in the Jenkins email notification configuration.
Here are the steps:
- Go to your Jenkins job configuration page and click on the "Configure" button.
- Scroll down to the "Post-build Actions" section and click on the "Add post-build action" button.
- Select "Email" from the list of available actions.
- Configure the email settings as desired (e.g. recipient, subject, body).
- In the "Attachments" section, click on the "Add file" button.
- Enter the path to the file you want to attach, using the following syntax:
path/to/your/file.txt
(replacepath/to/your/file.txt
with the actual path to your file). - You can also specify a custom location for the attachment by using the
file
syntax, like this:file:///path/to/your/file.txt
(note the triple forward slashes). - Click "Save" to save your changes.
Here's an example of what the email configuration might look like:
Email:
Recipient: <[email protected]>
Subject: My Job Build Result
Body: This is the body of the email.
Attachments:
- file:///path/to/your/file.txt
In this example, the file file.txt
located at /path/to/your/file.txt
will be attached to the email.
Note that you can also use environment variables in the attachment path, such as ${BUILD_ID}
or ${JOB_NAME}
, to make the attachment path dynamic.
Also, you can use the Attachments
section in the Jenkins email notification configuration to attach multiple files, by separating them with commas, like this:
Attachments:
- file:///path/to/your/file1.txt,file:///path/to/your/file2.txt
This will attach both file1.txt
and file2.txt
to the email.