This repository was archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/org/jenkinsci/plugins/typetalk/TypetalkSendStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.jenkinsci.plugins.typetalk; | ||
|
||
import hudson.Extension; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.BuildListener; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import org.jenkinsci.plugins.typetalk.api.Typetalk; | ||
import org.jenkinsci.plugins.typetalk.support.ResultSupport; | ||
import org.jenkinsci.plugins.typetalk.support.TypetalkMessage; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.inject.Inject; | ||
|
||
public class TypetalkSendStep extends AbstractStepImpl { | ||
|
||
private final @Nonnull String name; | ||
private final @Nonnull Long topicId; | ||
|
||
@Nonnull | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Nonnull | ||
public Long getTopicId() { | ||
return topicId; | ||
} | ||
|
||
@DataBoundConstructor | ||
public TypetalkSendStep(@Nonnull String name, @Nonnull Long topicId) { | ||
this.name = name; | ||
this.topicId = topicId; | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends AbstractStepDescriptorImpl { | ||
|
||
public DescriptorImpl() { | ||
super(TypetalkSendStepExecution.class); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "typetalkSend"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Notify Typetalk when the build fails"; | ||
} | ||
} | ||
|
||
public static class TypetalkSendStepExecution extends AbstractSynchronousNonBlockingStepExecution<Void> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Inject | ||
transient TypetalkSendStep step; | ||
|
||
@StepContextParameter | ||
transient TaskListener listener; | ||
|
||
@StepContextParameter | ||
transient Run run; | ||
|
||
/** | ||
* Almost same as {@link TypetalkNotifier#perform(AbstractBuild, Launcher, BuildListener)} | ||
*/ | ||
@Override | ||
protected Void run() throws Exception { | ||
ResultSupport resultSupport = new ResultSupport(); | ||
if (resultSupport.successFromPreviousBuild(run)) { | ||
return null; | ||
} | ||
|
||
listener.getLogger().println("Notifying build result to Typetalk..."); | ||
|
||
TypetalkMessage typetalkMessage = new ResultSupport().convertBuildToMessage(run); | ||
String message = typetalkMessage.buildMessageWithBuild(run); | ||
|
||
Typetalk.createFromName(step.name).postMessage(step.topicId, message); | ||
|
||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
36 changes: 25 additions & 11 deletions
36
src/main/java/org/jenkinsci/plugins/typetalk/support/ResultSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/resources/org/jenkinsci/plugins/typetalk/TypetalkSendStep/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
|
||
<f:entry title="${%Credential}"> | ||
<select class="setting-input" name="credential.name" description="Select configured credential"> | ||
<j:forEach var="credential" items="${app.getDescriptor('org.jenkinsci.plugins.typetalk.TypetalkNotifier').credentials}"> | ||
<f:option selected="${credential.name.equals(instance.name)}">${credential.name}</f:option> | ||
</j:forEach> | ||
</select> | ||
</f:entry> | ||
|
||
<f:entry title="${%Topic Number}" field="topicId"> | ||
<f:textbox /> | ||
</f:entry> | ||
|
||
</j:jelly> |
13 changes: 13 additions & 0 deletions
13
src/main/resources/org/jenkinsci/plugins/typetalk/TypetalkSendStep/help.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div> | ||
Use 'catchError' step in order to notify a build error certainly. An example is the following below. | ||
<p></p> | ||
<pre> | ||
catchError { | ||
sh 'compile' | ||
sh 'test' | ||
sh 'package' | ||
sh 'deploy' | ||
} | ||
typetalkSend name: 'demo', topicId: 1 | ||
</pre> | ||
</div> |