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

parse error: Invalid numeric literal #450

Closed
juvarabrera opened this issue May 10, 2024 · 2 comments
Closed

parse error: Invalid numeric literal #450

juvarabrera opened this issue May 10, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@juvarabrera
Copy link

juvarabrera commented May 10, 2024

Orb version:

4.9.3

What happened:

I'm trying to pass a custom message to slack orb. The custom message is already in json format

Expected behavior:

Should send the message in the Slack channel

Additional Information:

.circleci/config.yml

commands:
  notify_on_e2e_fail:
    description: Send slack notification on fail
    parameters:
      channel:
        type: string
      branch_pattern:
        type: string
        default: ".+"
      message:
        type: string
        default: ""
    steps:
      - slack/notify:
          event: fail
          channel: << parameters.channel >>
          custom: << parameters.message >>
          branch_pattern: << parameters.branch_pattern >>

. . .

jobs:
  myjob:
    steps:
      . . . # some steps that creates message.txt
      - notify_on_e2e_fail:
          channel: << parameters.slack_channel >>
          message: $(cat message.txt)

This is the value of message.txt

{"blocks": [{"type": "header","text": {"type": "plain_text","text": ":x: E2E Test Failed","emoji": true}},{"type": "section","text": {"type": "mrkdwn","text": "*Branch*: my/branch\n\n1 tests | ✅ 0 passed | :x: 1 failures | :x: 0 errors | 🔃 0 skipped"}},{"type": "divider"},{"type": "section","text": {"type": "mrkdwn","text": "*1. Test name*"}},{"type": "section","fields": [{"type": "mrkdwn","text": "*File*: path/to/file:123\n\n*Author*: Name <email>"},{"type": "mrkdwn","text": "*View Commit*: https://github.com/org_slug/repo/commit/abcdefg\n\n*Last updated*: 2024-01-01 00:00:00 +0800 (99 days ago)"}]},{"type": "section","fields": [{"type": "mrkdwn","text": "*File*: path/to/file:123\n\n*Author*: Name <email>"},{"type": "mrkdwn","text": "*View Commit*: https://github.com/org_slug/repo/commit/abcdefg\n\n*Last updated*: 2024-01-01 00:00:00 +0800 (99 days ago)"}]},{"type": "actions","elements": [{"type": "button","text": {"type": "plain_text","text": "View CircleCI Job","emoji": true},"value": "https://circleci.com/gh/org_slug/********/1234","action_id": "actionId-0"}]}]}

There are no issues in the Slack Block Kit Builder

This is the output of Slack orb:

BASH_ENV file: /tmp/.bash_env-663dc3f01fdefa2f8dbddf81-0-build
Does Not Exist. Skipping file execution
Posting Status
Checking For JQ + CURL
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6

Exited with code exit status 4

Is this even possible? Because I tried to pass the json string manually like this and it worked.

      - notify_on_e2e_fail:
          channel: << parameters.slack_channel >>
          message: "{ ... }"

I feel like it has something to do with this specific line

message: $(cat message.txt)

I also tried

message: |
  $(cat message.txt)

Thank you for checking 🙇

@juvarabrera juvarabrera added the bug Something isn't working label May 10, 2024
@marboledacci marboledacci self-assigned this Sep 9, 2024
@marboledacci
Copy link
Contributor

You cannot use bash in the parameters, the $(cat message.txt) is managed as a string and the orb is not designed to eval this.
You can get the value from a file though, you have two options:

  1. Use a step before to export the content of your file to an environment variable. More information here
  2. Use include, custom: <<include(message.txt)>>. More information here

@juvarabrera
Copy link
Author

juvarabrera commented Sep 18, 2024

Sorry, I forgot about this issue. I've fixed it using the following

...
      - run:
          name: Generate E2E Error Message
          when: on_fail
          command: |
            ...
            echo 'export MESSAGE="$(cat message.json)"' >> $BASH_ENV
      - notify_on_e2e_fail: # my own command
          channel: << parameters.slack_channel >>
          template: MESSAGE
...

https://discuss.circleci.com/t/exporting-environment-variables-from-sourced-scripts/4564/4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants