Skip to content
Merged
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
46 changes: 42 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.494</version>
<version>2.3</version>
</parent>

<artifactId>gatling</artifactId>
Expand All @@ -21,9 +21,9 @@
</licenses>

<scm>
<connection>scm:git:git@github.com:jenkinsci/gatling-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/gatling-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/gatling-plugin</url>
<connection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>

Expand Down Expand Up @@ -52,6 +52,19 @@
</developers>

<properties>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to
run. -->
<jenkins.version>1.651.2</jenkins.version>
<!-- Java Level to use. Java 7 required when using core >= 1.612 -->
<java.level>7</java.level>
<!-- Jenkins Test Harness version you use to test the plugin. -->
<!-- For Jenkins version >= 1.580.1 use JTH 2.x or higher. -->
<jenkins-test-harness.version>2.1</jenkins-test-harness.version>
<!-- Other properties you may want to use:
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
-->

<jackson.version>2.4.4</jackson.version>

<maven-compiler-plugin.version>3.0</maven-compiler-plugin.version>
Expand Down Expand Up @@ -83,6 +96,31 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- dependencies on Jenkins Pipeline plugins -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>1.14</version>
</dependency>

<!-- writeFile is useful for test -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>1.14</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/io/gatling/jenkins/GatlingBuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,43 @@

import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import jenkins.tasks.SimpleBuildStep;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class GatlingBuildAction implements Action {
/**
* An Action to add to a project/job's build/run page in the UI.
*
* Note that in order to be compatible with the new Jenkins Pipeline jobs,
* Actions that should be added to the project/job's page directly must be added
* by implementing the SimpleBuildStep.LastBuildAction interface, and encapsulating
* the project actions in the build action via the getProjectActions method.
*
* This is necessary and now preferred to the old approach of defining getProjectAction
* directly on the Publisher, because for a Pipeline job, Jenkins doesn't know ahead
* of time what actions will be triggered, and will never call the Publisher.getProjectAction
* method. Attaching it as a LastBuildAction means that it is discoverable once
* the Pipeline job has been run once.
*/
public class GatlingBuildAction implements Action, SimpleBuildStep.LastBuildAction {

private final AbstractBuild<?, ?> build;
private final Run<?, ?> build;
private final List<BuildSimulation> simulations;
private final List<GatlingProjectAction> projectActions;

public GatlingBuildAction(AbstractBuild<?, ?> build, List<BuildSimulation> sims) {
public GatlingBuildAction(Run<?, ?> build, List<BuildSimulation> sims) {
this.build = build;
this.simulations = sims;

List<GatlingProjectAction> projectActions = new ArrayList<>();
projectActions.add(new GatlingProjectAction(build.getParent()));
this.projectActions = projectActions;
}

public AbstractBuild<?, ?> getBuild() {
public Run<?, ?> getBuild() {
return build;
}

Expand Down Expand Up @@ -79,4 +102,8 @@ private BuildSimulation getSimulation(String simulationName) {
return null;
}

@Override
public Collection<? extends Action> getProjectActions() {
return this.projectActions;
}
}
18 changes: 8 additions & 10 deletions src/main/java/io/gatling/jenkins/GatlingProjectAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import static io.gatling.jenkins.PluginConstants.*;

import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.*;

import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -30,9 +28,9 @@

public class GatlingProjectAction implements Action {

private final AbstractProject<?, ?> project;
private final Job<?, ?> project;

public GatlingProjectAction(AbstractProject<?, ?> project) {
public GatlingProjectAction(Job<?, ?> project) {
this.project = project;
}

Expand All @@ -48,12 +46,12 @@ public String getUrlName() {
return URL_NAME;
}

public AbstractProject<?, ?> getProject() {
public Job<?, ?> getProject() {
return project;
}

public boolean isVisible() {
for (AbstractBuild<?, ?> build : getProject().getBuilds()) {
for (Run<?, ?> build : getProject().getBuilds()) {
GatlingBuildAction gatlingBuildAction = build.getAction(GatlingBuildAction.class);
if (gatlingBuildAction != null) {
return true;
Expand Down Expand Up @@ -98,10 +96,10 @@ public Long getValue(RequestReport requestReport) {
};
}

public Map<AbstractBuild<?, ?>, List<String>> getReports() {
Map<AbstractBuild<?, ?>, List<String>> reports = new LinkedHashMap<AbstractBuild<?, ?>, List<String>>();
public Map<Run<?, ?>, List<String>> getReports() {
Map<Run<?, ?>, List<String>> reports = new LinkedHashMap<Run<?, ?>, List<String>>();

for (AbstractBuild<?, ?> build : project.getBuilds()) {
for (Run<?, ?> build : project.getBuilds()) {
GatlingBuildAction action = build.getAction(GatlingBuildAction.class);
if (action != null) {
List<String> simNames = new ArrayList<String>();
Expand Down
49 changes: 24 additions & 25 deletions src/main/java/io/gatling/jenkins/GatlingPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
import hudson.Launcher;
import hudson.init.Initializer;
import hudson.init.InitMilestone;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Items;
import hudson.model.*;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import jenkins.tasks.SimpleBuildStep;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -39,10 +37,10 @@
import java.util.List;

@SuppressWarnings("unchecked")
public class GatlingPublisher extends Recorder {
public class GatlingPublisher extends Recorder implements SimpleBuildStep {

private final Boolean enabled;
private AbstractBuild<?, ?> build;
private Run<?, ?> build;
private PrintStream logger;


Expand All @@ -51,32 +49,31 @@ public GatlingPublisher(Boolean enabled) {
this.enabled = enabled;
}


@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
this.build = build;
logger = listener.getLogger();
if (enabled == null) {
logger.println("Cannot check Gatling simulation tracking status, reports won't be archived.");
logger.println("Please make sure simulation tracking is enabled in your build configuration !");
return true;
return;
}
if (!enabled) {
logger.println("Simulation tracking disabled, reports were not archived.");
return true;
return;
}

logger.println("Archiving Gatling reports...");
List<BuildSimulation> sims = saveFullReports(build.getWorkspace(), build.getRootDir());
List<BuildSimulation> sims = saveFullReports(workspace, build.getRootDir());
if (sims.isEmpty()) {
logger.println("No newer Gatling reports to archive.");
return true;
return;
}

GatlingBuildAction action = new GatlingBuildAction(build, sims);

build.addAction(action);

return true;
}

public boolean isEnabled() {
Expand All @@ -87,11 +84,6 @@ public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}

@Override
public Action getProjectAction(AbstractProject<?, ?> project) {
return new GatlingProjectAction(project);
}

private List<BuildSimulation> saveFullReports(FilePath workspace, File rootDir) throws IOException, InterruptedException {
FilePath[] files = workspace.list("**/global_stats.json");
List<FilePath> reportFolders = new ArrayList<FilePath>();
Expand All @@ -117,15 +109,24 @@ private List<BuildSimulation> saveFullReports(FilePath workspace, File rootDir)
List<BuildSimulation> simsToArchive = new ArrayList<BuildSimulation>();

File allSimulationsDirectory = new File(rootDir, "simulations");
if (!allSimulationsDirectory.exists())
allSimulationsDirectory.mkdir();
if (!allSimulationsDirectory.exists()) {
boolean mkdirResult = allSimulationsDirectory.mkdir();
if (! mkdirResult) {
logger.println("Could not create simulations archive directory '" + allSimulationsDirectory + "'");
return Collections.emptyList();
}
}

for (FilePath reportToArchive : reportsToArchive) {
String name = reportToArchive.getName();
int dashIndex = name.lastIndexOf('-');
String simulation = name.substring(0, dashIndex);
File simulationDirectory = new File(allSimulationsDirectory, name);
simulationDirectory.mkdir();
boolean mkdirResult = simulationDirectory.mkdir();
if (! mkdirResult) {
logger.println("Could not create simulation archive directory '" + simulationDirectory + "'");
return Collections.emptyList();
}

FilePath reportDirectory = new FilePath(simulationDirectory);

Expand Down Expand Up @@ -166,7 +167,7 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {

@Override
public String getDisplayName() {
return Messages.Title();
return Messages.title();
}

@Initializer(before = InitMilestone.PLUGINS_STARTED)
Expand All @@ -175,6 +176,4 @@ public static void addAliases() {
Items.XSTREAM2.addCompatibilityAlias("com.excilys.ebi.gatling.jenkins.GatlingBuildAction", GatlingBuildAction.class);
}
}


}
9 changes: 4 additions & 5 deletions src/main/java/io/gatling/jenkins/chart/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package io.gatling.jenkins.chart;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;

import java.io.IOException;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import hudson.model.Job;
import hudson.model.Run;
import io.gatling.jenkins.GatlingBuildAction;
import io.gatling.jenkins.BuildSimulation;
import io.gatling.jenkins.RequestReport;
Expand All @@ -36,9 +35,9 @@ public abstract class Graph<Y extends Number> {

private final ObjectMapper mapper = new ObjectMapper();

public Graph(AbstractProject<?, ?> project, int maxBuildsToDisplay) {
public Graph(Job<?, ?> project, int maxBuildsToDisplay) {
int numberOfBuild = 0;
for (AbstractBuild<?, ?> build : project.getBuilds()) {
for (Run<?, ?> build : project.getBuilds()) {
GatlingBuildAction action = build.getAction(GatlingBuildAction.class);

if (action != null) {
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/io/gatling/jenkins/steps/GatlingArchiverStep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2011-2015 GatlingCorp (http://gatling.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gatling.jenkins.steps;

import hudson.Extension;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;

/**
* Archiving for gatling reports.
*/
public class GatlingArchiverStep extends AbstractStepImpl {
@DataBoundConstructor
public GatlingArchiverStep() {}

@Extension
public static class DescriptorImpl extends AbstractStepDescriptorImpl {
public DescriptorImpl() { super(GatlingArchiverStepExecution.class); }

@Override
public String getFunctionName() {
return "gatlingArchive";
}

@Nonnull
@Override
public String getDisplayName() {
return "Archive Gatling reports";
}
}
}
Loading