Skip to content

Commit db3cf25

Browse files
committed
Releasing version 2.2.0 with support for notifying started and failed builds.
2 parents 1b83e64 + ba48840 commit db3cf25

8 files changed

Lines changed: 218 additions & 55 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build/
44
.gradle/
55
.idea/
66
out/
7+
.gradletasknamecache

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Tapadoo Limited
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.markdown

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A plugin for [TeamCity](http://www.jetbrains.com/teamcity/) to post notifications to [slack](https://slack.com/)
44

5-
It works by registering as a server listener, and posts to slack on successful builds finishing.
5+
It works by registering as a server listener, and posts to slack on build events like successful builds (optionally also builds starting and failing)
66

77
#Build Plugin
88

@@ -30,10 +30,11 @@ Add a new webhook integration. Make a note of the Token.
3030
###In TeamCity
3131

3232
Edit the main config file, usually `.BuildServer/config/main-config.xml` and add an element like so:
33+
3334
```
3435
<server rootURL="http://localhost:8111">
3536
...
36-
<slackNotifier>
37+
<slackNotifier postSuccessful="true" postFailed="false" postStarted="false" >
3738
<slackWebToken>testToken2</slackWebToken>
3839
<slackDefaultChannel>#general</slackDefaultChannel>
3940
<slackPostUrl>https://tapadoo.slack.com/services/hooks/incoming-webhook?token=</slackPostUrl>
@@ -43,6 +44,8 @@ Edit the main config file, usually `.BuildServer/config/main-config.xml` and add
4344
...
4445
```
4546

47+
You can set the attributes on slackNotifier element (postSuccessful,postFailed,postStarted) to decide that notifications you would like posted.
48+
4649
Replace the web token with the token from slack. Change the postUrl also to point to the right slack team. The url can be found in the webhook integraton page, just remove the token from the end. Change the logo url whatever you want.
4750

4851
This by default will post all builds to slack. you can tweak these on a project level though
@@ -62,10 +65,15 @@ Edit the plugin specific xml config, `plugin-settings.xml` probably somewhere in
6265

6366
#Note on TeamCity version support
6467

65-
I'm still using **TeamCity 7.1** , but a quick test on the free version of TeamCity 8 went ok
68+
I'm still using **TeamCity 7.1** , but a few tests on the free version of TeamCity 8 went fine, and it seems to work there also.
6669

6770
###Issues
6871

6972
* all xml config - needs web ui extensions for updating settings from GUI. Considering it.
7073
* channel can be changed per-project either by environmental variable (SLACK_CHANNEL) or by changing the project specific xml in the data directory. This could also use web ui extension UI for editing.
7174
* All or nothing notifications. By default, all builds are posted. It can be disabled per project, but not currently by build config.
75+
76+
77+
# License
78+
79+
MIT License.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply plugin: 'java'
77

88

99
sourceCompatibility = 1.5
10-
version = '2.1.2'
10+
version = '2.2.0'
1111

1212
configurations {
1313
deploy

src/main/java/com/tapadoo/slacknotifier/SlackConfigProcessor.java

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.tapadoo.slacknotifier;
22

33
import jetbrains.buildServer.serverSide.MainConfigProcessor;
4+
import org.jdom.Attribute;
5+
import org.jdom.DataConversionException;
46
import org.jdom.Element;
57

68
/**
@@ -15,11 +17,20 @@ public class SlackConfigProcessor implements MainConfigProcessor {
1517

1618
private static final java.lang.String PREF_CHILD_ELEMENT = "slackNotifier";
1719

20+
private static final java.lang.String ATTR_NAME_POST_SUCCESSFUL = "postSuccessful" ;
21+
private static final java.lang.String ATTR_NAME_POST_STARTED = "postStarted" ;
22+
private static final java.lang.String ATTR_NAME_POST_FAILED = "postFailed" ;
23+
24+
1825
private String token = "invalidToken";
1926
private String defaultChannel = "#general";
2027
private String postUrl;
2128
private String logoUrl;
2229

30+
private boolean postSuccessful = true ;
31+
private boolean postStarted = false ;
32+
private boolean postFailed = false ;
33+
2334
public SlackConfigProcessor()
2435
{
2536

@@ -30,6 +41,21 @@ public void init()
3041

3142
}
3243

44+
public boolean postSuccessful()
45+
{
46+
return postSuccessful ;
47+
}
48+
49+
public boolean postFailed()
50+
{
51+
return postFailed ;
52+
}
53+
54+
public boolean postStarted()
55+
{
56+
return postStarted ;
57+
}
58+
3359
public String getToken() {
3460
return token;
3561
}
@@ -65,10 +91,55 @@ public void setLogoUrl(String logoUrl) {
6591
public void readFrom(org.jdom.Element element) {
6692
Element mainConfigElement = element.getChild(PREF_CHILD_ELEMENT);
6793

94+
if( mainConfigElement == null )
95+
{
96+
token = "" ;
97+
postUrl = "http://localhost/?token=" ;
98+
return ;
99+
}
100+
68101
token = mainConfigElement.getChildText(PREF_KEY_SLACK_WEB_TOKEN);
69102
defaultChannel = mainConfigElement.getChildText(PREF_KEY_SLACK_DEF_CHANNEL);
70103
postUrl = mainConfigElement.getChildText(PREF_KEY_SLACK_POSTURL);
71104
logoUrl = mainConfigElement.getChildText(PREF_KEY_SLACK_LOGOURL);
105+
106+
Attribute postSuccessfulAttr = mainConfigElement.getAttribute(ATTR_NAME_POST_SUCCESSFUL);
107+
Attribute postStartedAttr = mainConfigElement.getAttribute(ATTR_NAME_POST_STARTED);
108+
Attribute postFailedAttr = mainConfigElement.getAttribute(ATTR_NAME_POST_FAILED);
109+
110+
if( postSuccessfulAttr != null )
111+
{
112+
try {
113+
postSuccessful = postSuccessfulAttr.getBooleanValue();
114+
}
115+
catch( DataConversionException ex )
116+
{
117+
postSuccessful = true ;
118+
}
119+
}
120+
121+
if( postStartedAttr != null )
122+
{
123+
try {
124+
postStarted = postStartedAttr.getBooleanValue();
125+
}
126+
catch( DataConversionException ex )
127+
{
128+
postStarted = false ;
129+
}
130+
}
131+
132+
if( postFailedAttr != null )
133+
{
134+
try {
135+
postFailed = postFailedAttr.getBooleanValue();
136+
}
137+
catch( DataConversionException ex )
138+
{
139+
postFailed = false ;
140+
}
141+
}
142+
72143
}
73144

74145
public void writeTo(org.jdom.Element element) {
@@ -87,7 +158,7 @@ public void writeTo(org.jdom.Element element) {
87158
mainConfigElement.addContent(postUrlElement);
88159
mainConfigElement.addContent(logoUrlElement);
89160

90-
element.addContent(webTokenElement);
161+
element.addContent(mainConfigElement);
91162

92163

93164
}

0 commit comments

Comments
 (0)