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

Enable all triggers for slack #13

Closed
coolya opened this issue Oct 6, 2015 · 19 comments
Closed

Enable all triggers for slack #13

coolya opened this issue Oct 6, 2015 · 19 comments
Labels
Milestone

Comments

@coolya
Copy link

coolya commented Oct 6, 2015

Is there any particular reason why I can't customize the events to sent when I select slack JSON payload?

We are running tons of builds a day and I only want to notify the slack channel when the status changes from success to failure and vice versa.

@netwolfuk
Copy link
Member

The new templates support is still alpha and I haven't implemented all the build events yet. This is the file that needs a few more entries in it. https://github.com/tcplugins/tcWebHooks/blob/custom-templates/tcwebhooks-core/src/main/resources/webhook/teamcity/payload/template/SlackComWebHookTemplate.properties

@coolya
Copy link
Author

coolya commented Oct 6, 2015

I see. Is a pull request for adding this welcome? :)

@netwolfuk
Copy link
Member

Yes. Very welcome. Also, the text in that file needs better wording. One probably expects something better than "all your failures are belong to us" :-)

@netwolfuk
Copy link
Member

The names of the properties are based on the following https://github.com/tcplugins/tcWebHooks/blob/custom-templates/tcwebhooks-core/src/main/java/webhook/teamcity/BuildStateEnum.java
You need two versions of each. One with branch in the name and one without. The plugin will choose based on whether your build is setup to know about your branches.

@netwolfuk
Copy link
Member

Hi. I'm just wondering how you got on with those templates. I have a bit of time this weekend so could have a crack at it if you haven't had a chance.

@netwolfuk netwolfuk added this to the v1.1 milestone Dec 7, 2015
@netwolfuk netwolfuk added the bug label Dec 7, 2015
@netwolfuk
Copy link
Member

@coolya Do you have slack messages that you think tcWebhooks should emulate? Even a screenshot would be a good start.

@nbergen
Copy link

nbergen commented Aug 12, 2016

FWIW, here's my success message. I think it could be more terse.

{
    "text" : "${buildName} SUCCESS",
    "attachments" : [{
            "pretext" : "${buildName} ${projectId} ${branchDisplayName}",
            "fallback" : "${buildName} SUCCESS",
            "title" : "Build Log #${buildNumber}",
            "title_link" : "${buildStatusUrl}&tab=buildLog",
            "color" : "good"
        }
    ]
}

(with "'s replaced with ", of course)

image

@netwolfuk
Copy link
Member

Ah. Interesting. I would have made it much more verbose so thanks for the feedback. Maybe it would be a good idea to have a detailed and a compact version.

@netwolfuk
Copy link
Member

@nbergen. I presume you are overriding these in webhook-templates.xml. Is there a chance you could post that whole file? I'll add them as compact.

@nbergen
Copy link

nbergen commented Aug 12, 2016

More terse vertical-space wise, but ran out of time to configure it.

I actually just dropped it in plugins-settings.xml for now. At some point I'll have time to revisit the configuration and clean it up.

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <webhooks enabled="true">
    <webhook url="https://hooks.slack.com/<url>" enabled="true" format="nvpairs">
      <states>
        <state type="buildBroken" enabled="false" />
        <state type="beforeBuildFinish" enabled="false" />
        <state type="buildFailed" enabled="true" />
        <state type="buildFinished" enabled="true" />
        <state type="buildStarted" enabled="false" />
        <state type="responsibilityChanged" enabled="false" />
        <state type="buildInterrupted" enabled="false" />
        <state type="buildSuccessful" enabled="false" />
        <state type="buildFixed" enabled="false" />
      </states>
      <build-types enabled-for-all="true" enabled-for-subprojects="true" />
      <parameters>
        <param name="payload" value="{     &quot;text&quot; : &quot;FAILURE&quot;,  &quot;attachments&quot; : [{             &quot;pretext&quot; : &quot;${projectId} [${branchDisplayName}]&quot;,    &quot;fallback&quot; : &quot;${buildName} FAILED&quot;,             &quot;title&quot; : &quot;Build Log #${buildNumber}&quot;,             &quot;title_link&quot; : &quot;${buildStatusUrl}&amp;tab=buildLog&quot;,    &quot;text&quot; : &quot;${buildName} triggered by ${triggeredBy} has a status of ${buildResult}&quot;,    &quot;color&quot; : &quot;danger&quot;   }  ] } " />
      </parameters>
    </webhook>
    <webhook url="https://hooks.slack.com/<url>" enabled="true" format="nvpairs">
      <states>
        <state type="buildBroken" enabled="false" />
        <state type="beforeBuildFinish" enabled="false" />
        <state type="buildFailed" enabled="false" />
        <state type="buildFinished" enabled="false" />
        <state type="buildStarted" enabled="false" />
        <state type="responsibilityChanged" enabled="false" />
        <state type="buildInterrupted" enabled="false" />
        <state type="buildSuccessful" enabled="true" />
        <state type="buildFixed" enabled="true" />
      </states>
      <build-types enabled-for-all="true" enabled-for-subprojects="true" />
      <parameters>
        <param name="payload" value="{     &quot;text&quot; : &quot;SUCCESS&quot;,  &quot;attachments&quot; : [{             &quot;pretext&quot; : &quot;${projectId} [${branchDisplayName}]&quot;,    &quot;fallback&quot; : &quot;${buildName} SUCCESS&quot;,             &quot;title&quot; : &quot;Build Log #${buildNumber}&quot;,             &quot;title_link&quot; : &quot;${buildStatusUrl}&amp;tab=buildLog&quot;,&quot;text&quot; : &quot;${buildName}  &quot; ,   &quot;color&quot; : &quot;good&quot;   }  ] } " />
      </parameters>
    </webhook>
  </webhooks>
</settings>

v: 0.9.80.83

@netwolfuk
Copy link
Member

Cool. Thanks so much. I see you're on 0.9.x.x so can't take advantage of the new template features of the 1.1alpha versions. Therefore what you're doing is the best way for that version. I can still take your ideas and use them as the basis for a 1.1 template :-)

@nbergen
Copy link

nbergen commented Aug 12, 2016

As I was trudging around our TC filesystem, I admit I was a little envious of what looks likes UI to edit these in the alpha ;)

@netwolfuk
Copy link
Member

Don't worry. Not all the ui is done for 1.1 so one still can't actually edit the payload in the ui yet. I'm making progress on the REST api and then can write that ui to talk to that. I just wish I had more time in the evenings.

@netwolfuk
Copy link
Member

netwolfuk commented Aug 12, 2016

Having said that, choosing from a predefined list of templates does work. And customising templates editing webhook-templates.xml does too.

@aaronjensen
Copy link

@netwolfuk are there instructions on customizing webhooks-templates.xml? I don't have that file so I'm not sure what would go in it

@aaronjensen
Copy link

Ah, found an example https://github.com/tcplugins/tcWebHooks/blob/v1.1-alpha6.109.134/tcwebhooks-core/src/test/resources/webhook-templates.xml

I'll try that out. Oh and hi @nbergen, hope all is well 😄

@netwolfuk
Copy link
Member

This is essentially the same as #61 so once this is done, MatterMost support should just work,

@netwolfuk
Copy link
Member

netwolfuk commented Dec 3, 2017

@aaronjensen @nbergen BTW the UI is done in alpha11. So you can edit templates much more easily.
Requires the REST API zip installed as well. See https://github.com/tcplugins/tcWebHooks/wiki/Installing#download-the-plugins

netwolfuk added a commit that referenced this issue Dec 6, 2017
- Added more buildStates. 
- Normal slack.com template more verbose
- Compact slack.com template more compact.
- Takes advantage of the ${capitalise()} and ${substr()} macros.
@netwolfuk
Copy link
Member

I have updated the two templates:
The standard slack.com one. Now more verbose:
image

And the slack.com-compact one. Now more terse:
image

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

4 participants