-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from jenkinsci/report_status_to_vsts_steps
Report pending and completion status to the associated TFS/Team Services commit
- Loading branch information
Showing
13 changed files
with
577 additions
and
1 deletion.
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
64 changes: 64 additions & 0 deletions
64
src/main/java/hudson/plugins/tfs/VstsCompletedStatusPostBuildAction.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,64 @@ | ||
package hudson.plugins.tfs; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.tfs.util.VstsStatus; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.BuildStepMonitor; | ||
import hudson.tasks.Notifier; | ||
import hudson.tasks.Publisher; | ||
import jenkins.tasks.SimpleBuildStep; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A _Post-Build Action_ that reports the completion status of an associated build to VSTS. | ||
*/ | ||
public class VstsCompletedStatusPostBuildAction extends Notifier implements SimpleBuildStep { | ||
|
||
@DataBoundConstructor | ||
public VstsCompletedStatusPostBuildAction() { | ||
|
||
} | ||
|
||
@Override | ||
public void perform( | ||
@Nonnull final Run<?, ?> run, | ||
@Nonnull final FilePath workspace, | ||
@Nonnull final Launcher launcher, | ||
@Nonnull final TaskListener listener | ||
) throws InterruptedException, IOException { | ||
try { | ||
VstsStatus.createFromRun(run); | ||
} | ||
catch (final Exception e) { | ||
e.printStackTrace(listener.error("Error while trying to update completion status in VSTS")); | ||
} | ||
} | ||
|
||
@Override | ||
public BuildStepMonitor getRequiredMonitorService() { | ||
// we don't need the outcome of any previous builds for this step | ||
return BuildStepMonitor.NONE; | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> { | ||
|
||
@Override | ||
public boolean isApplicable(final Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Set completion status for VSTS commit or pull request"; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/hudson/plugins/tfs/VstsPendingStatusBuildStep.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,56 @@ | ||
package hudson.plugins.tfs; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.tfs.util.VstsStatus; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.Builder; | ||
import jenkins.tasks.SimpleBuildStep; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A _Build Step_ that reports the status of an associated build as "Pending" to VSTS. | ||
*/ | ||
public class VstsPendingStatusBuildStep extends Builder implements SimpleBuildStep { | ||
|
||
@DataBoundConstructor | ||
public VstsPendingStatusBuildStep() { | ||
|
||
} | ||
|
||
@Override | ||
public void perform( | ||
@Nonnull final Run<?, ?> run, | ||
@Nonnull final FilePath workspace, | ||
@Nonnull final Launcher launcher, | ||
@Nonnull final TaskListener listener | ||
) throws InterruptedException, IOException { | ||
try { | ||
VstsStatus.createFromRun(run); | ||
} | ||
catch (final Exception e) { | ||
e.printStackTrace(listener.error("Error while trying to update pending status in VSTS")); | ||
} | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends BuildStepDescriptor<Builder> { | ||
|
||
@Override | ||
public boolean isApplicable(Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Set pending status for VSTS commit or pull request"; | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/hudson/plugins/tfs/model/GitStatusStateMorpher.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,37 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.ezmorph.MorphException; | ||
import net.sf.ezmorph.ObjectMorpher; | ||
|
||
public class GitStatusStateMorpher implements ObjectMorpher { | ||
|
||
public static final GitStatusStateMorpher INSTANCE = new GitStatusStateMorpher(); | ||
|
||
private GitStatusStateMorpher() { | ||
|
||
} | ||
|
||
@Override | ||
public Object morph(final Object value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
|
||
if (!supports(value.getClass())) { | ||
throw new MorphException(value.getClass() + " is not supported"); | ||
} | ||
|
||
final String s = value.toString(); | ||
return GitStatusState.caseInsensitiveValueOf(s); | ||
} | ||
|
||
@Override | ||
public Class morphsTo() { | ||
return GitStatusState.class; | ||
} | ||
|
||
@Override | ||
public boolean supports(Class clazz) { | ||
return String.class.isAssignableFrom(clazz); | ||
} | ||
} |
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
Oops, something went wrong.