Skip to content
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

Slack send reports invalid json error when reading from file for the blocks #851

Open
svg7 opened this issue Oct 26, 2022 · 0 comments
Open
Labels

Comments

@svg7
Copy link

svg7 commented Oct 26, 2022

Jenkins and plugins versions report

Environment
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

K8 on AWS

Reproduction steps

This is my slack notify step which is part of my jenkins pipeline and extracted only the error step. Below I have the "slackTemplate2.text" file which contains my "blocks" and I read that in my pipeline replacing the values for only one placeholder "VERTICALNAME".

When we read from the file in step 6 below it errors out and the error is mentioned below. The same blocks will work if we define in a variable as below

def blocks = [
[
"type": "header",
"text": [
"type": "plain_text",
"text": "Financial Test Execution Summary"
]
]
]
slackNotify step
stage('Slack Notify') {

  1.    echo 'Sending Slack Notification...'
    
  2.    def verticalName = "Financial"
    
  3. sh """
    
    1.    sed "s|VERTICALNAME|$verticalName|"  "${WORKSPACE}/Industries-automation/slackTemplate2.text" | tee "${WORKSPACE}/Automation/target/json-reports/results.text"
      
  4.        """
    
  5.  def slackMsg = readFile "${WORKSPACE}/Automation/target/json-reports/results.text"
    
7.    slackSend channel: params.slackChannel, blocks: slackMsg
}

slackTemplate2.text
[
[
"type": "header",
"text": [
"type": "plain_text",
"text": "VERTICALNAME Test Execution Summary"
]
]
]

Error
ERROR: Slack notification failed with exception: net.sf.json.JSONException: Invalid JSON String
22:00:57 ERROR: Slack notification failed with exception: {"ok":false,"error":"no_text"}
22:00:57 ERROR: Slack notification failed. See Jenkins logs for details.

Expected Results

The result should be the same, whether reading from the file or from the variable for the blocks variable that we pass to slackSend command.

If we use the readFile and then pass the value to the "blocks" in slackSend command it throws error.

Actual Results

ERROR: Slack notification failed with exception: net.sf.json.JSONException: Invalid JSON String
22:00:57 ERROR: Slack notification failed with exception: {"ok":false,"error":"no_text"}
22:00:57 ERROR: Slack notification failed. See Jenkins logs for details.

Anything else?

No response

@svg7 svg7 added the bug label Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant