Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Edit the main config file, usually `.BuildServer/config/main-config.xml` and add
<slackDefaultChannel>#general</slackDefaultChannel>
<slackPostUrl>https://hooks.slack.com/services/YYYYYY/XXXXXXX/ZZZZZZZZZZZZ</slackPostUrl>
<slackLogoUrl>http://build.tapadoo.com/img/icons/TeamCity32.png</slackLogoUrl>
<buildFailedPermalink>http://build.tapadoo.com/viewLog.html?buildTypeId=XXXXXXX&amp;buildId=lastFinished</buildFailedPermalink>
</slackNotifier>
...
...
Expand All @@ -64,6 +65,17 @@ Edit the plugin specific xml config, `plugin-settings.xml` probably somewhere in
</settings>
```

Alternatively, you may also override the alert selections that were specified in main-config.xml:

```
<settings>
<slackSettings enabled="true" postSuccessful="false" postFailed="true" postStarted="false">
<channel>#blah</channel>
<logoUrl>http://host/somelogo.png</logoUrl>
</slackSettings>
</settings>
```

#Note on TeamCity version support

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. Users have reported it working on version 9 also.
Expand All @@ -72,9 +84,10 @@ I'm still using **TeamCity 7.1** , but a few tests on the free version of TeamCi

* all xml config - needs web ui extensions for updating settings from GUI. Considering it.
* channel can be changed per-project either by environmental variable (SLACK_CHANNEL (env var may be broken)) or by changing the project specific xml in the data directory. This could also use web ui extension UI for editing.
* All or nothing notifications. By default, all builds are posted. It can be disabled per project, but not currently by build config.

* Project-level notification selection only. Notification settings per individual build configuration are not supported.


# License

MIT License.
MIT License.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'java'


sourceCompatibility = 1.6
version = '2.4.0'
version = '2.5.0'

configurations {
deploy
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/tapadoo/slacknotifier/SlackConfigProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SlackConfigProcessor implements MainConfigProcessor {
public static final String PREF_KEY_SLACK_DEF_CHANNEL = "slackDefaultChannel";
public static final String PREF_KEY_SLACK_POSTURL = "slackPostUrl";
public static final String PREF_KEY_SLACK_LOGOURL = "slackLogoUrl";
public static final String PREF_KEY_BUILD_FAILED_PERMALINK = "buildFailedPermalink";

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

Expand All @@ -23,6 +24,7 @@ public class SlackConfigProcessor implements MainConfigProcessor {
private String defaultChannel = "#general";
private String postUrl;
private String logoUrl;
private String buildFailedPermalink;

private boolean postSuccessful = true ;
private boolean postStarted = false ;
Expand Down Expand Up @@ -61,6 +63,14 @@ public void setDefaultChannel(String defaultChannel) {
this.defaultChannel = defaultChannel;
}

public String getBuildFailedPermalink(){
return buildFailedPermalink;
}

public void setBuildFailedPermalink(String permalink){
this.buildFailedPermalink = permalink;
}

public String getPostUrl() {
return postUrl;
}
Expand Down Expand Up @@ -89,6 +99,7 @@ public void readFrom(org.jdom.Element element) {
defaultChannel = mainConfigElement.getChildText(PREF_KEY_SLACK_DEF_CHANNEL);
postUrl = mainConfigElement.getChildText(PREF_KEY_SLACK_POSTURL);
logoUrl = mainConfigElement.getChildText(PREF_KEY_SLACK_LOGOURL);
buildFailedPermalink = mainConfigElement.getChildText(PREF_KEY_BUILD_FAILED_PERMALINK);

Attribute postSuccessfulAttr = mainConfigElement.getAttribute(ATTR_NAME_POST_SUCCESSFUL);
Attribute postStartedAttr = mainConfigElement.getAttribute(ATTR_NAME_POST_STARTED);
Expand Down Expand Up @@ -135,12 +146,14 @@ public void writeTo(org.jdom.Element element) {
Element defChannelElement = new Element(PREF_KEY_SLACK_DEF_CHANNEL);
Element postUrlElement = new Element(PREF_KEY_SLACK_POSTURL);
Element logoUrlElement = new Element(PREF_KEY_SLACK_LOGOURL);
Element buildFailedPermalinkElement = new Element(PREF_KEY_BUILD_FAILED_PERMALINK);

defChannelElement.setText(defaultChannel);

mainConfigElement.addContent(defChannelElement);
mainConfigElement.addContent(postUrlElement);
mainConfigElement.addContent(logoUrlElement);
mainConfigElement.addContent(buildFailedPermalinkElement);

element.addContent(mainConfigElement);

Expand Down
81 changes: 58 additions & 23 deletions src/main/java/com/tapadoo/slacknotifier/SlackProjectSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ public class SlackProjectSettings implements ProjectSettings {
public static final String ELEMENT_LOGO_URL = "logoUrl";
public static final String ATTR_ENABLED = "enabled";
public static final String ELEMENT_CHANNEL = "channel";

private static final java.lang.String ATTR_NAME_POST_SUCCESSFUL = "postSuccessful";
private static final java.lang.String ATTR_NAME_POST_STARTED = "postStarted";
private static final java.lang.String ATTR_NAME_POST_FAILED = "postFailed";

private String projectId;
private String channel;
private String logoUrl;
private boolean enabled = true ;

private boolean enabled = true;
private Boolean postSuccessful = null;
private Boolean postStarted = null;
private Boolean postFailed = null;

public SlackProjectSettings(String projectId) {
this.projectId = projectId ;
this.projectId = projectId;
}

public SlackProjectSettings()
{
public SlackProjectSettings() {

}

Expand All @@ -43,11 +51,22 @@ public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}

public boolean isEnabled()
{
public boolean isEnabled() {
return this.enabled;
}

public boolean postSuccessfulSet() { return this.postSuccessful != null;}

public boolean postSuccessfulEnabled() { return this.postSuccessful; }

public boolean postStartedSet() { return this.postStarted != null;}

public boolean postStartedEnabled() { return this.postStarted; }

public boolean postFailedSet() { return this.postFailed != null;}

public boolean postFailedEnabled() { return this.postFailed; }

public void dispose() {

}
Expand All @@ -57,25 +76,20 @@ public void readFrom(Element element) {
Element logoElement = element.getChild(ELEMENT_LOGO_URL);
Attribute enabledAttr = element.getAttribute(ATTR_ENABLED);

if( enabledAttr != null )
{
try {
enabled = enabledAttr.getBooleanValue() ;
} catch (DataConversionException e) {
enabled = true ;
}
}
else
{
enabled = true ;
}
Attribute postSuccessfulAttr = element.getAttribute(ATTR_NAME_POST_SUCCESSFUL);
Attribute postStartedAttr = element.getAttribute(ATTR_NAME_POST_STARTED);
Attribute postFailedAttr = element.getAttribute(ATTR_NAME_POST_FAILED);

enabled = tryGetBooleanAttributeValue(enabledAttr);
postSuccessful = tryGetBooleanAttributeValue(postSuccessfulAttr);
postFailed = tryGetBooleanAttributeValue(postFailedAttr);
postStarted = tryGetBooleanAttributeValue(postStartedAttr);

if( channelElement != null ) {
if (channelElement != null) {
this.channel = channelElement.getText();
}

if( logoElement != null )
{
if (logoElement != null) {
this.logoUrl = logoElement.getText();
}
}
Expand All @@ -88,11 +102,32 @@ public void writeTo(Element element) {
Element logoUrlElement = new Element(ELEMENT_LOGO_URL);
logoUrlElement.setText(this.logoUrl);

Attribute enabledAttr = new Attribute(ATTR_ENABLED,Boolean.toString(enabled)) ;
element.setAttribute( enabledAttr );
Attribute enabledAttr = new Attribute(ATTR_ENABLED, Boolean.toString(enabled));
element.setAttribute(enabledAttr);

Attribute postSuccessfulAttr = new Attribute(ATTR_NAME_POST_SUCCESSFUL, Boolean.toString(postSuccessful));
element.setAttribute(postSuccessfulAttr);

Attribute postFailedAttr = new Attribute(ATTR_NAME_POST_FAILED, Boolean.toString(postFailed));
element.setAttribute(postFailedAttr);

Attribute postStartedAttr = new Attribute(ATTR_NAME_POST_STARTED, Boolean.toString(postStarted));
element.setAttribute(postStartedAttr);

element.addContent(channelElement);
element.addContent(logoUrlElement);
}

private Boolean tryGetBooleanAttributeValue(Attribute attr) {
if (attr != null) {
try {
return attr.getBooleanValue();
} catch (DataConversionException e) {
return null;
}
}

return null;
}

}
Loading