Skip to content
This repository was archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from jenkinsci/make-pipeline
Browse files Browse the repository at this point in the history
pipeline
  • Loading branch information
ikikko authored May 13, 2017
2 parents c31d162 + 6ab08e3 commit 40f0102
Show file tree
Hide file tree
Showing 22 changed files with 553 additions and 145 deletions.
31 changes: 10 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
buildscript {
repositories {
// The plugin is currently only available via the Jenkins
// Maven repository, but has dependencies in Maven Central.
mavenCentral()
maven {
url 'http://repo.jenkins-ci.org/releases/'
}
}
dependencies {
classpath 'org.jenkins-ci.tools:gradle-jpi-plugin:0.7.2'
}
plugins {
id 'org.jenkins-ci.jpi' version '0.18.1'
}

apply plugin: 'org.jenkins-ci.jpi'
apply plugin: 'eclipse'
apply plugin: 'idea'

group = 'org.jenkins-ci.plugins'
version = '1.1.1-SNAPSHOT'
description = 'Typetalk Plugin'
archivesBaseName = 'typetalk'

dependencies {
compile 'com.google.http-client:google-http-client-jackson:1.17.0-rc',
'com.google.oauth-client:google-oauth-client:1.17.0-rc'
testCompile 'org.spockframework:spock-core:0.7-groovy-1.8',
'cglib:cglib-nodep:2.2.2',
'org.objenesis:objenesis:1.3'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.0@jar',
'org.jenkins-ci.plugins.workflow:workflow-job:2.0@jar'
jenkinsTest 'org.jenkins-ci.plugins:ant:1.2@jar',
'org.jenkins-ci.plugins:mailer:1.1@jar'
'org.jenkins-ci.plugins:mailer:1.1@jar',
'org.jenkins-ci.plugins.workflow:workflow-step-api:2.0@jar',
'org.jenkins-ci.plugins.workflow:workflow-job:2.0@jar',
'org.jenkins-ci.plugins.workflow:workflow-api:2.0@jar' // dependency for workflow-job
}

jenkinsPlugin {
coreVersion = '1.509'
coreVersion = '1.651.2'
shortName = 'typetalk'
displayName = 'Typetalk Plugin'
url = 'https://wiki.jenkins-ci.org/display/JENKINS/Typetalk+Plugin'
gitHubUrl = 'https://github.com/jenkinsci/typetalk-plugin'
Expand All @@ -49,7 +42,3 @@ jenkinsPlugin {
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Dec 28 22:38:17 JST 2014
#Sun May 15 00:42:41 JST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.typetalk.api.Typetalk;
import org.jenkinsci.plugins.typetalk.support.Emoji;
import org.jenkinsci.plugins.typetalk.support.TypetalkMessage;
import org.jenkinsci.plugins.typetalk.delegate.BuildWrapperDelegate;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
Expand All @@ -37,46 +33,15 @@ public TypetalkBuildWrapper(String name, String topicNumber, boolean notifyStart

@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
if (notifyStart) {
listener.getLogger().println("Notifying build start to Typetalk...");

String message;
if (StringUtils.isBlank(notifyStartMessage)) {
TypetalkMessage typetalkMessage = new TypetalkMessage(Emoji.LOUDSPEAKER, "Build start");
message = typetalkMessage.buildMessageWithBuild(build);
} else{
message = build.getEnvironment(listener).expand(notifyStartMessage);
}
Long topicId = Long.valueOf(topicNumber);

Typetalk.createFromName(name).postMessage(topicId, message);
}
final BuildWrapperDelegate delegate = new BuildWrapperDelegate(name, Long.valueOf(topicNumber), listener, build);
delegate.notifyStart(notifyStart, notifyStartMessage);

return new Environment() {
@Override
public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
if (notifyEnd && isSuccessBuild(build)) {
listener.getLogger().println("Notifying build end to Typetalk...");

String message;
if (StringUtils.isBlank(notifyEndMessage)) {
TypetalkMessage typetalkMessage = new TypetalkMessage(Emoji.MEGA, "Build end");
message = typetalkMessage.buildMessageWithBuild(build);
} else {
message = build.getEnvironment(listener).expand(notifyEndMessage);
}
Long topicId = Long.valueOf(topicNumber);

Typetalk.createFromName(name).postMessage(topicId, message);
}

delegate.notifyEnd(notifyEnd, notifyEndMessage);
return true;
}

private boolean isSuccessBuild(AbstractBuild build) {
// When there is nothing failure (equals success), getResult hasn't been set yet.
return build.getResult() == null || build.getResult().equals(Result.SUCCESS);
}
};
}

Expand Down
30 changes: 3 additions & 27 deletions src/main/java/org/jenkinsci/plugins/typetalk/TypetalkNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;
import hudson.util.Secret;
import net.sf.json.JSONObject;
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.typetalk.delegate.NotifyDelegate;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

Expand All @@ -28,7 +25,7 @@ public class TypetalkNotifier extends Notifier {
public final String topicNumber;

@DataBoundConstructor
public TypetalkNotifier(String name, String topicNumber, boolean notifyWhenSuccess) {
public TypetalkNotifier(String name, String topicNumber) {
this.name = name;
this.topicNumber = topicNumber;
}
Expand All @@ -41,31 +38,10 @@ public BuildStepMonitor getRequiredMonitorService() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {

if (successFromPreviousBuild(build)) {
return true;
}

listener.getLogger().println("Notifying build result to Typetalk...");

TypetalkMessage typetalkMessage = new ResultSupport().convertBuildToMessage(build);
String message = typetalkMessage.buildMessageWithBuild(build);
Long topicId = Long.valueOf(topicNumber);

Typetalk.createFromName(name).postMessage(topicId, message);

new NotifyDelegate(name, Long.valueOf(topicNumber), listener, build).notifyResult();
return true;
}

private boolean successFromPreviousBuild(AbstractBuild<?, ?> build) {
if (build.getPreviousBuild() == null) {
return build.getResult().equals(Result.SUCCESS);
} else {
return build.getResult().equals(Result.SUCCESS)
&& build.getPreviousBuild().getResult().equals(Result.SUCCESS);
}
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.jenkinsci.plugins.typetalk.delegate;

import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.typetalk.api.Typetalk;
import org.jenkinsci.plugins.typetalk.support.Emoji;
import org.jenkinsci.plugins.typetalk.support.TypetalkMessage;

import java.io.IOException;

public class BuildWrapperDelegate {

private final String name;

private final Long topicId;

private final TaskListener listener;

private final Run run;

public BuildWrapperDelegate(String name, Long topicId, TaskListener listener, Run run) {
this.name = name;
this.topicId = topicId;
this.listener = listener;
this.run = run;
}

public void notifyStart(boolean notifyStart, String notifyStartMessage) throws IOException, InterruptedException {
if (notifyStart) {
listener.getLogger().println("Notifying build start to Typetalk...");

String message;
if (StringUtils.isBlank(notifyStartMessage)) {
TypetalkMessage typetalkMessage = new TypetalkMessage(Emoji.LOUDSPEAKER, "Build start");
message = typetalkMessage.buildMessageWithBuild(run);
} else {
message = run.getEnvironment(listener).expand(notifyStartMessage);
}

Typetalk.createFromName(name).postMessage(topicId, message);
}
}

public void notifyEnd(boolean notifyEnd, String notifyEndMessage) throws IOException, InterruptedException {
if (notifyEnd && isSuccessBuild(run)) {
listener.getLogger().println("Notifying build end to Typetalk...");

String message;
if (StringUtils.isBlank(notifyEndMessage)) {
TypetalkMessage typetalkMessage = new TypetalkMessage(Emoji.MEGA, "Build end");
message = typetalkMessage.buildMessageWithBuild(run);
} else {
message = run.getEnvironment(listener).expand(notifyEndMessage);
}

Typetalk.createFromName(name).postMessage(topicId, message);
}
}

private boolean isSuccessBuild(Run run) {
// When there is nothing failure (equals success), getResult hasn't been set yet.
return run.getResult() == null || run.getResult().equals(Result.SUCCESS);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jenkinsci.plugins.typetalk.delegate;

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 java.io.IOException;

public class NotifyDelegate {

private final String name;

private final Long topicId;

private final TaskListener listener;

private final Run run;

public NotifyDelegate(String name, Long topicId, TaskListener listener, Run run) {
this.name = name;
this.topicId = topicId;
this.listener = listener;
this.run = run;
}

public void notifyResult() throws IOException {
ResultSupport resultSupport = new ResultSupport();
if (resultSupport.isSuccessFromSuccess(run)) {
return;
}

listener.getLogger().println("Notifying build result to Typetalk...");

TypetalkMessage typetalkMessage = resultSupport.convertBuildToMessage(run);
String message = typetalkMessage.buildMessageWithBuild(run);

Typetalk.createFromName(name).postMessage(topicId, message);
}

}
Loading

0 comments on commit 40f0102

Please sign in to comment.