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

Template for x-www-form-urlencoded #120

Closed
kymikoloco opened this issue Oct 17, 2018 · 3 comments
Closed

Template for x-www-form-urlencoded #120

kymikoloco opened this issue Oct 17, 2018 · 3 comments
Milestone

Comments

@kymikoloco
Copy link

Expected Behavior

Some API endpoints don't take application/json payloads, and there needs to be a way to send different content types to them (x-www-form-urlencoded, namely)

Current Behavior

Get a cryptic error from the API endpoint claiming the content wasn't sent.

Steps to Reproduce (for bugs)

  1. Sign up for chat.zulip.org
  2. Create an incoming webhook bot, taking note of the API key and email
  3. Create a new json template
  4. Add a Build Event Template with Build Successful and the following JSON code
{
    "type": "private",
    "to": "[email protected]",
    "content":"${buildStatus}"
}
  1. Create a new WebHook for a project with the url https://chat.zulip.org/api/v1/messages
  2. Under Extra Config set to Basic Auth with the Username the email address of the bot and password the API Key of the bot
  3. Under Preview & Test send a test webhook event
  4. Bad Request (400) should be sent out. Debug Logs should say {"var_name":"type","result":"error","code":"REQUEST_VARIABLE_MISSING","msg":"Missing 'type' argument"}

Your Environment

  • tcWebHooks Version: 1.1-RC2.245.377
  • tcWebHooks REST API Version: 1.1-RC2.245.377
  • TeamCity Version: TeamCity Professional 2018.1.2 (build 58537)
  • TeamCity server Operating System: Ubuntu 18.04.1 LTS x86_64
  • Are you using a WebHook Template?: Yes, created from help in Show response body for failed request #115

Example Configuration (xml)

/opt/.BuildServer/config/webhook-templates.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<webhook-templates>
    <webhook-template id="zulip-message" enabled="true" rank="21" format="nvpairs">
        <template-description>Send a Zulip message to a stream or a user</template-description>
        <template-tool-tip>POSTs a very simple zulip message</template-tool-tip>
        <preferred-date-format></preferred-date-format>
        <templates max-id="3">
            <template id="0">
      <!-- template does nothing for application/x-www-form-urlencoded right now -->
                <template-text use-for-branch-template="false">{
    "type": "private",
    "to": "[email protected]",
"content":"${buildStatus}"
}</template-text>
                <branch-template-text>{
    "type": "private",
    "to": "[email protected]",
"content":"${buildStatus}"
}</branch-template-text>
                <states>
                    <state type="buildStarted" enabled="true"/>
                    <state type="buildSuccessful" enabled="true"/>
                </states>
            </template>
        </templates>
    </webhook-template>
</webhook-templates>

opt/.BuildServer/config/projects/Nightly/pluginData/plugin-settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <webhooks enabled="true">
    <webhook url="https://chat.zulip.org/api/v1/messages" enabled="true" format="nvpairs" template="zulip-message">
      <states>
        <state type="buildStarted" enabled="true" />
        <state type="beforeBuildFinish" enabled="false" />
        <state type="responsibilityChanged" enabled="false" />
        <state type="changesLoaded" enabled="false" />
        <state type="buildInterrupted" enabled="false" />
        <state type="buildSuccessful" enabled="true" />
        <state type="buildBroken" enabled="false" />
        <state type="buildFinished" enabled="true" />
        <state type="buildFailed" enabled="false" />
        <state type="buildFixed" enabled="false" />
      </states>
      <build-types enabled-for-all="true" enabled-for-subprojects="false">
        <build-type id="bt8" />
      </build-types>
      <!-- Parameters here do nothing -->
      <parameters>
        <param name="content" value="${buildStatus}" />
        <param name="to" value="[email protected]" />
        <param name="type" value="private" />
      </parameters>
      <auth enabled="true" type="userpass" preemptive="true">
        <auth-parameters>
          <param name="username" value="[email protected]" />
          <param name="password" value="API_KEY" />
          <param name="realm" value="" />
        </auth-parameters>
      </auth>
      <headers>
        <header name="Authorization" value="Basic base64stuff==" />
        <header name="Content-Type" value="application/x-www-form-urlencoded" />
      </headers>
    </webhook>
  </webhooks>
</settings>

/opt/.BuildServer/config/projects/Nightly/project-config.xml

Contains the parameters for the Nightly Project that zulip expects and nvpairs will send

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" parent-id="Example" uuid="ab9a8dc4-8d23-48ea-84a5-c3c594ab2a54" xsi:noNamespaceSchemaLocation="http://www.jetbrains.com/teamcity/schemas/2018.1/project-config.xsd">
  <name>Nightly</name>
  <description>Nightly builder. Cleans all sources and deploys to artifact storage</description>
  <parameters>
    <param name="webhook.content" value="TeamCity version ${system.teamcity.version} running as user ${env.LOGNAME} - ${buildStatus}" />
    <param name="webhook.to" value="[email protected]" />
    <param name="webhook.type" value="private" />
  </parameters>
  <cleanup />
</project>
@netwolfuk netwolfuk added this to the v1.2 milestone Oct 18, 2018
netwolfuk added a commit that referenced this issue Dec 10, 2018
Just put your variables into the body of the template lines in the
format "name=${variable}" (without the quotes).

eg,
				${item3}=${item4}
				bar=foo
				${item5}=${item6}
netwolfuk added a commit that referenced this issue Dec 10, 2018
Just put your variables into the body of the template lines in the
format "name=${variable}" (without the quotes).

eg,
				${item3}=${item4}
				bar=foo
				${item5}=${item6}
netwolfuk added a commit that referenced this issue Dec 10, 2018
Just put your variables into the body of the template lines in the
format "name=${variable}" (without the quotes).

eg,
				${item3}=${item4}
				bar=foo
				${item5}=${item6}
netwolfuk added a commit that referenced this issue Dec 10, 2018
Just put your variables into the body of the template lines in the
format "name=${variable}" (without the quotes).

eg,
				${item3}=${item4}
				bar=foo
				${item5}=${item6}
netwolfuk added a commit that referenced this issue Dec 11, 2018
Just put your variables into the body of the template lines in the
format "name=${variable}" (without the quotes).

eg,
				${item3}=${item4}
				bar=foo
				${item5}=${item6}
netwolfuk added a commit that referenced this issue Dec 11, 2018
Just put your variables into the body of the template lines in the
format "name=${variable}" (without the quotes).

eg,
				${item3}=${item4}
				bar=foo
				${item5}=${item6}
@netwolfuk
Copy link
Member

Hi @kymikoloco
If you want to try a recent build from master, this is now supported. https://teamcity.jetbrains.com/viewType.html?buildTypeId=WebHooksAndOtherPlugins_TcWebHooks&branch_WebHooksAndOtherPlugins=%3Cdefault%3E&tab=buildTypeStatusDiv

Edit your template to look like a java properties file. eg

				${item3}=${item4}
				bar=foo
				${item5}=${item6}

Properties are one per line.

@netwolfuk
Copy link
Member

This will be released as part of tcWebHooks version 1.2.x

@netwolfuk
Copy link
Member

1.2.0 alpha.1 released which includes this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants