tcplugins / tcWebHooks

WebHooks plugin for Teamcity. Supports many build states and payload formats.
https://netwolfuk.wordpress.com/category/teamcity/tcplugins/tcwebhooks/
157 stars 30 forks source link

JSON Velocity template produces invalid JSON? #245

Closed andreycha closed 4 months ago

andreycha commented 4 months ago

Hi, I'm using the plugin to post messages to Mattermost. I've added a standard JSON template:

{
    "channel_id": "some_id",
    "message": "##### :red_circle: Build failed\n\n| Build | Branch | Version | Status |\n|:---|:---:|:---:|:---|\n| ${projectName} / ${buildName} | ${branchDisplayName} | #${buildNumber} | [${buildStatus}](${buildStatusUrl}) |"
}

Works like a charm: image

Now I wanted to extend it with information from $(changes) variable using Velocity and switched the template payload format to JSON Velocity. I haven't done any changes in the template text itself, but Mattermost already started to return 400 Bad Request and preview started to also give an error:

image

Checked the documentation once again but didn't find anything. Would be grateful if you can point to where the issue is. Plugin version is 2.0.0.

netwolfuk commented 4 months ago

A couple of interesting things here:

  1. Editing the template and then testing from the Template editor half works. At least it doesn't give that json exception
  2. Testing from the webhook edit dialog gives me the same as you.

However, if I remove the #### from the template it works ok. I think # is a keyword in velocity. Does it need to be there for mattermost? Oddly, it is fine for the build number, but not the set at the beginning.

image

netwolfuk commented 4 months ago

So this is what I have and it's working for me when I use the local test endpoint http://localhost:8111/webhooks/endpoint.html.

{
    "channel_id": "some_id",
    "message": ":red_circle: Build failed\n\n| Build | Branch | Version | Status |\n|:---|:---:|:---:|:---|\n| ${projectName} / ${buildName} | ${branchDisplayName} | #${buildNumber} | [${buildStatus}](${buildStatusUrl}) |"
}

Note; i have not tested this with Mattermost.

andreycha commented 4 months ago

Doh >.< Thanks, this is it! Thought Velocity is a bit more intelligent, luckily there are different ways to escape #.