Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gricey432 authored Jan 13, 2017
2 parents b73e8c4 + 8b96c38 commit b55674d
Show file tree
Hide file tree
Showing 31 changed files with 1,202 additions and 198 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#2.1 release notes

New Features:

* Added Jenkins Credentials support (#247)
* Added support for display-url-api; will allow Blue Ocean to change display URLs (#245)
* Added support for @here and other @mentions (#241)
* Reduced log verbosity (#252)
* Updated `@Extension` ordinal value to force earlier migration process (#261)

UI Improvements:

* Added credentials selection widget (#247)

Bug Fixes:

* Fixe for Security issue [JENKINS-35503](https://issues.jenkins-ci.org/browse/JENKINS-35503) (#247)
* Fixed documentation for Pipeline step (#220)

# 2.0.1 release notes

Bug Fixes:
Expand Down
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
# Slack plugin for Jenkins - [![Build Status][jenkins-status]][jenkins-builds] [![Slack Signup][slack-badge]][slack-signup]
Slack plugin for Jenkins [![Build Status][jenkins-status]][jenkins-builds] [![Slack Signup][slack-badge]][slack-signup]
----------------------------------------------------------------

Started with a fork of the HipChat plugin:
Provides Jenkins notification integration with Slack.

https://github.com/jlewallen/jenkins-hipchat-plugin
## Install Instructions

Which was, in turn, a fork of the Campfire plugin.
1. Get a Slack account: https://slack.com/
2. Configure the Jenkins integration: https://my.slack.com/services/new/jenkins-ci
3. Install this plugin on your Jenkins server
4. Configure it in your Jenkins job (and optionally as global configuration) and **add it as a Post-build action**.

#### Security

Use Jenkins Credentials and a credential ID to configure the Slack integration token. It is a security risk to expose your integration token using the previous *Integration Token* setting.

Create a new ***Secret text*** credential:
![image](https://cloud.githubusercontent.com/assets/983526/17971588/6c26dfa0-6aa9-11e6-808c-3e139446e013.png)


Select that credential as the value for the ***Integration Token Credential ID*** field:
![image](https://cloud.githubusercontent.com/assets/983526/17971458/ec296bf6-6aa8-11e6-8d19-06d9f1c9d611.png)


#### Bot user option
This plugin supports sending notifications via bot users. You can enable bot user support from both
global and project configurations. If the notification will be sent to a user via direct message,
default integration sends it via @slackbot, you can use this option if you want to send messages via a bot user.
You need to provide credentials of the bot user for integration token credentials to use this feature.

#### Jenkins Pipeline Support

Includes [Jenkins Pipeline](https://github.com/jenkinsci/workflow-plugin) support as of version 2.0:

```
slackSend color: 'good', message: 'Message from Jenkins Pipeline'
```

# Jenkins Instructions

1. Get a Slack account: https://slack.com/
2. Configure the Jenkins integration: https://my.slack.com/services/new/jenkins-ci
3. Install this plugin on your Jenkins server
4. Configure it in your Jenkins job and **add it as a Post-build action**.

# Developer instructions
### Developer instructions

Install Maven and JDK. This was last build with Maven 3.2.5 and OpenJDK
1.7.0\_75 on KUbuntu 14.04.
Expand Down
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<artifactId>slack</artifactId>
<packaging>hpi</packaging>
<version>2.1-SNAPSHOT</version>
<version>2.2-SNAPSHOT</version>
<name>Slack Notification Plugin</name>
<description>A Build status publisher that notifies channels on a Slack team</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Slack+Plugin</url>
Expand All @@ -45,8 +45,20 @@
<url>https://github.com/jenkinsci/slack-plugin</url>
<tag>head</tag>
</scm>

<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/releases</url>
</repository>
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>display-url-api</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -85,6 +97,16 @@
<version>1.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.25</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
<version>1.1</version>
</dependency>
<!-- only here to prevent from being included inside hpi for hudson parent, not needed by project at all -->
<dependency>
<groupId>log4j</groupId>
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/jenkins/plugins/slack/ActiveNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
import hudson.triggers.SCMTrigger;
import hudson.util.LogTaskListener;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.logging.Level.INFO;
import static java.util.logging.Level.SEVERE;
Expand Down Expand Up @@ -216,6 +221,8 @@ String getBuildStatusMessage(AbstractBuild r, boolean includeTestSummary, boolea

public static class MessageBuilder {

private static final Pattern aTag = Pattern.compile("(?i)<a([^>]+)>(.+?)</a>");
private static final Pattern href = Pattern.compile("\\s*(?i)href\\s*=\\s*(\"([^\"]*\")|'[^']*'|([^'\">\\s]+))");
private static final String STARTING_STATUS_MESSAGE = "Starting...",
BACK_TO_NORMAL_STATUS_MESSAGE = "Back to normal",
STILL_FAILING_STATUS_MESSAGE = "Still Failing",
Expand Down Expand Up @@ -322,7 +329,7 @@ private MessageBuilder startMessage() {
}

public MessageBuilder appendOpenLink() {
String url = notifier.getBuildServerUrl() + build.getUrl();
String url = DisplayURLProvider.get().getRunURL(build);
message.append(" (<").append(url).append("|Open>)");
return this;
}
Expand Down Expand Up @@ -386,14 +393,34 @@ private String createBackToNormalDurationString(){
return Util.getTimeSpanString(backToNormalDuration);
}

public String escape(String string) {
private String escapeCharacters(String string) {
string = string.replace("&", "&amp;");
string = string.replace("<", "&lt;");
string = string.replace(">", "&gt;");

return string;
}

private String[] extractReplaceLinks(Matcher aTag, StringBuffer sb) {
int size = 0;
List<String> links = new ArrayList<String>();
while (aTag.find()) {
Matcher url = href.matcher(aTag.group(1));
if (url.find()) {
aTag.appendReplacement(sb,String.format("{%s}", size++));
links.add(String.format("<%s|%s>", url.group(1).replaceAll("\"", ""), aTag.group(2)));
}
}
aTag.appendTail(sb);
return links.toArray(new String[size]);
}

public String escape(String string) {
StringBuffer pattern = new StringBuffer();
String[] links = extractReplaceLinks(aTag.matcher(string), pattern);
return MessageFormat.format(escapeCharacters(pattern.toString()), links);
}

public String toString() {
return message.toString();
}
Expand Down
Loading

0 comments on commit b55674d

Please sign in to comment.