Hello guys
Trying to integrate slack messages in my pipeline but receiving an "Invalid JSON provided" error.
This is my pipeline:
pipelines:
default:
- step:
name: Slack Notification
script:
- apt-get update && apt-get install gettext-base
- envsubst < ./pipeline/slack/payloads/payload_firebase_beta.json.template > ./pipeline/slack/payloads/payload_firebase_beta.json
- pipe: atlassian/slack-notify:2.0.0
variables:
WEBHOOK_URL: $WEBHOOK_URL
PRETEXT: 'New Android beta release was published to Firebase! 🚀🚀🚀'
PAYLOAD_FILE: ./pipeline/slack/payloads/payload_firebase_beta.json
payload_firebase_beta.json
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "$WEBSITE"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Test mrkdwn text"
}
}
]
}
payload_firebase_beta.json.template
WEBSITE="test website"
Error:
INFO: Starting with payload provided in PAYLOAD_FILE...
INFO: Sending notification to Slack...
✖ Failed to parse PAYLOAD_FILE payload.json: invalid JSON provided.
Thank you in advance
Thank you for reaching out to the community.
I've tested the same on my end.
However, using the JSON format you provided works fine on my end.
I tried providing an invalid JSON format to the Pipes script and I was able to reproduce the same error message.
For this, would it be possible for you to check the JSON format after the command envsubst?
- envsubst < ./pipeline/slack/payloads/payload_firebase_beta.json.template > ./pipeline/slack/payloads/payload_firebase_beta.json - cat ./pipeline/slack/payloads/payload_firebase_beta.json
Let me know how it goes.
Regards,
Mark C
Sorry for a bit late response.
It overwrites the payload_firebase_beta.json file with this text.
WEBSITE="test website"
It replaced the whole file instead of the specific veriable.
That's why it says that the JSON is invalid
Which envsubst command are you using that works from your side?
Should my file with variables (template) be in a template format or txt?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay
I found the reason why it didn't work.
I should have first export them as ENVIRONMENT VARS and only after that use it with envsubst.
- export RELEASE_DATE=$(date +'%b %d, %Y')
- envsubst < ./pipeline/slack/payloads/payload_firebase_beta.json.template > ./pipeline/slack/payloads/payload_firebase_beta.json
Now it works!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Edgar Khimich
Glad to know you've found the reason why it didn't work.
Thank you also for sharing your solution.
Let me know if you have further questions.
Regards,
Mark C
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.