-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to escape new line character in message? #106
Comments
@mrrobot47 cc |
I want to know how to this too |
If anyone is looking for a workaround or solution whatever you call my response, I solved this issue by below steps in my Github Actions pipeline. Feel free to edit - name: Prepare Slack Message
if: ${{ success() }}
id: slack-message-creator
run: |
SLACK_MESSAGE="*Version:* 12345
*Testing Groups:* my_test_group
*Change Log:* my_change_log"
echo "::set-output name=slack-message::${SLACK_MESSAGE//$'\n'/'%0A'}"
- name: Notify Release Channel
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2.1.3
env:
SLACK_USERNAME: '<your_username>'
SLACK_WEBHOOK: <your_slack_hook>
SLACK_ICON: <your_icon>
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: <your_title>
SLACK_MESSAGE: '${{ steps.slack-message-creator.outputs.slack-message }}'
MSG_MINIMAL: true |
If someone is using @nuhkoca script, he missing " at the end of SLACK_MESSAGE |
@choyzer thanks for warning, I updated it! |
@nuhkoca Hm, I think I'm missing something. How are you getting |
@Julian88Tex If I understand you correctly, |
@nuhkoca ah, so is there |
@nuhkoca actually nevermind I figured out what was going on. Apparently having an inline code format character was messing it up. Works:
Doesn't Work:
|
@Julian88Tex glad you fixed. But here
every line is a new line right? So it corresponds to |
@nuhkoca thanks yeah it just wasn't interpreting it in that way with the ` characters. I guess just the way bash operates. |
The In order to solve it, I use the syntax for Multiline strings So, now my code looks something like this: - name: Summary
id: summary
run: |
slack_message="* Total tests:* 1
* Passes:* 2
* Failed:* 3
* Gist report: 4"
echo 'slack-message<<EOF' >> $GITHUB_OUTPUT
echo "$slack_message" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: *******
SLACK_USERNAME: Demo - Integration Test on yada yada
SLACK_TITLE: "Summary"
SLACK_MESSAGE: ${{ steps.summary.outputs.slack-message }}
SLACK_ICON: https://avatars.githubusercontent.com/u/95714513?s=400&u=a00afc56cfc57ef9aa0fab1540f70a8507df3e96
SLACK_COLOR: ${{job.status}} Hope this might help anyone out there. |
This didn't work for be. The bolding. |
hi @nuhkoca thanks for the example, unfortunately Im still not seeing multi-line output in slack. this is what im doing (shortened...): - name: Get log between tags
id: release-log
shell: bash
run: |
...
gitcommits=$(git log previousTag..HEAD --pretty=format:"%h %s - %an %B %n" -- ${{ inputs.logRoot }}/)
echo "### Git commits since Last Tag 📒" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
while IFS= read -r line; do
echo $line >> $GITHUB_STEP_SUMMARY
done <<< "$gitcommits"
echo "RELEASE-LOG=${gitcommits//$'\n'/'%0A'}" >> "$GITHUB_OUTPUT"
- name: Slack notification for successful deployment
if: ${{ always() && steps.s3-deploy.outcome == 'success' }}
uses: rtCamp/action-slack-notify@v2.2.0
env:
...
SLACK_MESSAGE: "Log: ${{ steps.release-log.outputs.RELEASE-LOG }}"
Im printing out the job summary which is coming out well inside the Github interface. |
Hi, whoever encounters this question in the future. I am talking to you. So, new environment variable is available Source: #164 |
For anyone who might need it, the way I managed to escape line breaks is using @nuhkoca's code but instead replacing I assume this works by replacing the newline character with the literal string
|
I have a well-detailed Slack message for our releases but without a break,
message
andtitle
look too adjacent to each other. That's the reason, I want to have a break betweentitle
andmessage
but seems you always trim whitespaces in themessage
field, am I right? I tried below but none of them worked.For example,
**(asteriks)
character works to make text bold. Please find screenshot for your reference.The text was updated successfully, but these errors were encountered: