Hi @kazurayam@katalonautomation@katalonautomation
I am trying to send email after my test suite execution in azure pipeline using azure communication services, but unable to attach the run time generated .html file. Though i am able to locate the file successfully but getting error “Mismatch: 1 standard attachments + 0 inline attachments does not equal 0 attachment types” . Please help.
Please refer Below script detail and error screenshot:
Script used in azure pipeline YAML:
task: Bash@3
displayName: ‘Send Email Notification’
condition: always()
inputs:
targetType: ‘inline’
script: |
export AZURE_COMMUNICATION_CONNECTION_STRING=“endpoint=;accesskey=”
ls -l /d/a/1/a/allreports///////.html | tail -n 1
# Get the latest generated HTML file
REPORT_PATH=$(ls -t D:/a/1/a/allreports///////.html | head -n 1)
REPORT_NAME=$(basename “$REPORT_PATH”)
if [[ -z "$REPORT_PATH" ]]; then
echo "Error: No HTML report found."
exit 1
fi
az communication email send \
--connection-string "$AZURE_COMMUNICATION_CONNECTION_STRING" \
--sender "noreply@xyz.com" \
--to "nitin@xyz.com" \
--subject "Pipeline Execution Status" \
--text "The pipeline has completed successfully. Please find the report attached." \
--attachments "[{\"name\": \"$REPORT_NAME\", \"path\": \"$REPORT_PATH\", \"contentType\": \"text/html\"}]"
To resolve the attachment mismatch error when sending emails via Azure Communication Services in your pipeline, follow these steps:
1. Fix JSON Formatting for Attachments
Use single quotes to encapsulate the JSON array and ensure proper escaping:
az communication email send \
--connection-string "$AZURE_COMMUNICATION_CONNECTION_STRING" \
--sender "noreply@xyz.com" \
--to "nitin@xyz.com" \
--subject "Pipeline Execution Status" \
--text "The pipeline has completed successfully. Please find the report attached." \
--attachments '[{\"name\": \"'"$REPORT_NAME"'\", \"path\": \"'"$REPORT_PATH"'\", \"contentType\": \"text/html\"}]'
2. Verify File Paths
Use Absolute Paths Explicitly
# For Windows agents (use backslashes and escape them)
REPORT_PATH="D:\\a\\1\\a\\allreports\\\\\\.html"
# For Linux agents
REPORT_PATH="/d/a/1/a/allreports///////.html"
Check File Exists Before Sending
if [[ ! -f "$REPORT_PATH" ]]; then
echo "Error: Report file not found at $REPORT_PATH"
exit 1
fi
3. Simplify File Selection
Avoid ambiguity by using a precise filename pattern:
This is a technical support community forum where our users are trying to connect and support other users as much as they can in their capacity. Hope this helps!
Thanks Dinesh for the detailed response.
I am using window based agent and when I give path with the ‘\’ (D:\a\1\a\allreports\\\\\\\.html) then it has not been identified but when gives path In other style D:/a/1/a/allreports///////.html then it is identifying the right html file.
But, again I am getting the same mismatch issue. Please find the attached error logs and my complete yaml file:
The path expression “D:\a...” here does not make sense to me at all. Therefore I replied “I don’t know Azure” in a previous post. I really didn’t understand your posts.
But I found in the raw code of your post, you wanted to write
D:\a\1\a\allreports\*\*\*\*\*\*\*.html
This path expression is completely different from what you actually presented in the previous posts. Your previous posts confuse us — the guys who visited this forum.
Backslash character \ confuses everyone in many places (yaml, json, markdown).
But a savior comes, as you noticed:
This finding suggests that Azure will accept forward slash chacater / instead of \ as file separator character.
I would recommend you to avoid backslash characters completely. You should use / instead in the pipeline definition yaml file. Things will become much easier.
Yes it is simpler thanks for suggesting but my file is correctly identified if you see the log error which i attached earlier, main issue is Mismatching of file during attachment. Tried many solutions but nothing works.