Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline support #1

Merged
merged 9 commits into from
Jun 25, 2017
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
19 changes: 18 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.14</version>
<version>2.22</version>
<relativePath />
</parent>
<artifactId>applitools-eyes</artifactId>
Expand Down Expand Up @@ -33,6 +33,7 @@
<jenkins.version>1.625.3</jenkins.version>
<!-- Java Level to use. Java 7 required when using core >= 1.612 -->
<java.level>7</java.level>
<plugins.workflow.version>1.15</plugins.workflow.version>
</properties>

<developers>
Expand All @@ -43,7 +44,23 @@
</developer>
</developers>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${plugins.workflow.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${plugins.workflow.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>m.g.o-public</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.applitools.jenkins;

import hudson.model.AbstractBuild;
import hudson.model.Action;

/**
Expand All @@ -21,6 +20,4 @@ public String getDisplayName() {
public String getUrlName() {
return null;
}

public abstract AbstractBuild<?, ?> getBuild();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Code for the build page.
*/
public class ApplitoolsBuildWrapper extends BuildWrapper implements Serializable {
public String serverURL = DescriptorImpl.APPLITOOLS_DEFAULT_URL;
public String serverURL = ApplitoolsCommon.APPLITOOLS_DEFAULT_URL;

@DataBoundConstructor
public ApplitoolsBuildWrapper(String serverURL) {
Expand All @@ -31,7 +31,7 @@ public ApplitoolsBuildWrapper(String serverURL) {
this.serverURL = serverURL.trim();
}
} else {
this.serverURL = DescriptorImpl.APPLITOOLS_DEFAULT_URL;
this.serverURL = ApplitoolsCommon.APPLITOOLS_DEFAULT_URL;
}
}

Expand All @@ -44,61 +44,22 @@ public Environment setUp(final AbstractBuild build, Launcher launcher, final Bui

@Override
public void buildEnvVars(Map<String, String> env) {
buildEnvVariablesForExternalUsage(env, build, listener);
ApplitoolsCommon.buildEnvVariablesForExternalUsage(env, build, listener, serverURL);
}
};
}

private void runPreBuildActions(final AbstractBuild build, final BuildListener listener) throws IOException, InterruptedException
private void runPreBuildActions(final Run build, final BuildListener listener) throws IOException, InterruptedException
{
listener.getLogger().println("Starting Applitools Eyes pre-build (server URL is '" + this.serverURL + "')");

updateProjectProperties(build);
addApplitoolsActionToBuild(build);
build.save();
ApplitoolsCommon.integrateWithApplitools(build, serverURL);

listener.getLogger().println("Finished Applitools Eyes pre-build");
}

private void buildEnvVariablesForExternalUsage(Map<String, String> env, final AbstractBuild build, final BuildListener listener)
{
String batchId = ApplitoolsStatusDisplayAction.generateBatchId(build.getProject().getDisplayName(), build.getNumber(), build.getTimestamp());
String batchName = build.getProject().getDisplayName();
ApplitoolsEnvironmentUtil.outputVariables(listener, env, serverURL, batchName, batchId);
}

private void updateProjectProperties(final AbstractBuild build) throws IOException
{
boolean found = false;
for (Object property:build.getProject().getAllProperties())
{
if (property instanceof ApplitoolsProjectConfigProperty)
{
((ApplitoolsProjectConfigProperty)property).setServerURL(this.serverURL);
found = true;
break;
}
}
if (!found)
{
JobProperty jp = new ApplitoolsProjectConfigProperty(this.serverURL);
build.getProject().addProperty(jp);
}
build.getProject().save();
}

private void addApplitoolsActionToBuild(final AbstractBuild build)
{
ApplitoolsStatusDisplayAction buildAction = build.getAction(ApplitoolsStatusDisplayAction.class);
if (buildAction == null) {
buildAction = new ApplitoolsStatusDisplayAction(build);
build.addAction(buildAction);
}
}

@Extension
public static final class DescriptorImpl extends Descriptor<BuildWrapper> {
public static final String APPLITOOLS_DEFAULT_URL = "https://eyes.applitools.com";
public DescriptorImpl() {
load();
}
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/applitools/jenkins/ApplitoolsCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.applitools.jenkins;

import hudson.model.BuildListener;
import hudson.model.JobProperty;
import hudson.model.Run;
import hudson.model.TaskListener;

import java.io.IOException;
import java.util.Map;

/**
* Created by addihorowitz on 6/1/17.
*/
public class ApplitoolsCommon {

public final static String APPLITOOLS_DEFAULT_URL = "https://eyes.applitools.com";

public static void integrateWithApplitools(Run run, String serverURL
) throws IOException
{
updateProjectProperties(run, serverURL);
addApplitoolsActionToBuild(run);
run.save();
}
private static void updateProjectProperties(Run run, String serverURL
) throws IOException
{
boolean found = false;
for (Object property:run.getParent().getAllProperties())
{
if (property instanceof ApplitoolsProjectConfigProperty)
{
((ApplitoolsProjectConfigProperty)property).setServerURL(serverURL);
found = true;
break;
}
}
if (!found)
{
JobProperty jp = new ApplitoolsProjectConfigProperty(serverURL);
run.getParent().addProperty(jp);
}
run.getParent().save();
}

private static void addApplitoolsActionToBuild(final Run build)
{
ApplitoolsStatusDisplayAction buildAction = build.getAction(ApplitoolsStatusDisplayAction.class);
if (buildAction == null) {
buildAction = new ApplitoolsStatusDisplayAction(build);
build.addAction(buildAction);
}
}

public static void buildEnvVariablesForExternalUsage(Map<String, String> env, final Run build, final TaskListener listener, String serverURL)
{
String projectName = build.getParent().getDisplayName();
String batchId = ApplitoolsStatusDisplayAction.generateBatchId(projectName, build.getNumber(), build.getTimestamp());
String batchName = projectName;
ApplitoolsEnvironmentUtil.outputVariables(listener, env, serverURL, batchName, batchId);
}


}
18 changes: 18 additions & 0 deletions src/main/java/com/applitools/jenkins/ApplitoolsEnv.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.applitools.jenkins;
import java.io.Serializable;
/**
* Created by addihorowitz on 5/20/17.
*/
public class ApplitoolsEnv implements Serializable{
public String serverURL = ApplitoolsCommon.APPLITOOLS_DEFAULT_URL;

public String getServerURL() {
return serverURL;
}

public void setServerURL(String serverURL) {
if (serverURL != null && !serverURL.isEmpty())
this.serverURL = serverURL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.applitools.jenkins;
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander;
import java.util.Map;
import java.util.HashMap;
import javax.annotation.Nonnull;
import hudson.EnvVars;
import java.io.IOException;

/**
* Created by addihorowitz on 5/7/17.
*/
public class ApplitoolsEnvironmentExpander extends EnvironmentExpander {
private static final long serialVersionUID = 1;
private final Map<String, String> overrides;

ApplitoolsEnvironmentExpander(HashMap<String, String> overrides) {
this.overrides = overrides;

}

@Override
public void expand(@Nonnull EnvVars env) throws IOException, InterruptedException {
env.overrideAll(overrides);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.applitools.jenkins;

import hudson.model.BuildListener;
import hudson.model.TaskListener;

import java.util.Map;

Expand All @@ -9,7 +10,7 @@
*/
public class ApplitoolsEnvironmentUtil {

public static void outputVariables(final BuildListener listener, Map<String, String> env, String serverURL, String batchName, String batchId) {
public static void outputVariables(final TaskListener listener, Map<String, String> env, String serverURL, String batchName, String batchId) {
final String APPLITOOLS_BATCH_NAME = "BATCH_NAME";
final String APPLITOOLS_BATCH_ID = "BATCH_ID";
final String APPLITOOLS_PROJECT_SERVER_URL = "PROJECT_SERVER_URL";
Expand All @@ -28,7 +29,7 @@ public static void outputVariables(final BuildListener listener, Map<String, Str
}
}

public static void outputEnvironmentVariable(final BuildListener listener, Map<String, String> env, String key, String value, boolean overwrite) {
public static void outputEnvironmentVariable(final TaskListener listener, Map<String, String> env, String key, String value, boolean overwrite) {
String prefix = "APPLITOOLS_";

if (env.get(key) == null || overwrite) {
Expand All @@ -37,4 +38,5 @@ public static void outputEnvironmentVariable(final BuildListener listener, Map<S
listener.getLogger().println(keyName + " = '" + value + "'");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import hudson.model.AbstractProject;
import hudson.model.Job;

import java.io.Serializable;

/**
* Encapsulates Applitools plugin configuration.
*/
public class ApplitoolsProjectConfigProperty extends JobProperty<AbstractProject<?, ?>> {
public class ApplitoolsProjectConfigProperty extends JobProperty<AbstractProject<?, ?>> implements Serializable{
private String serverURL;

public ApplitoolsProjectConfigProperty(String serverURL) {
Expand Down
Loading