Failed to parse PAYLOAD_FILE payload.json: invalid JSON provided

Edgar Khimich September 16, 2021

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 

1 answer

1 vote
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 20, 2021

Hi @Edgar Khimich

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

Edgar Khimich September 27, 2021

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?
 

Edgar Khimich September 27, 2021

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!

Like Oleksandr Kyrdan likes this
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 27, 2021

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

Like Oleksandr Kyrdan likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events