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

Idos/trello bugfix 2201 missing custom batch #2

Open
wants to merge 89 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
08448bd
Update README.md
addihorowitz Sep 1, 2016
20309a2
Update README.md
addihorowitz Sep 1, 2016
b4a09be
Removed incorrect reference.
danielputerman Sep 11, 2016
9c4b93b
Updated version.
danielputerman Sep 11, 2016
7d95e9a
Updated Jelly files according to Jenkins requirements for XSS protect…
danielputerman Sep 12, 2016
e0b4d09
Removed dead store + inline doc.
danielputerman Sep 12, 2016
4ab6b56
[maven-release-plugin] prepare release applitools-eyes-1.1
danielputerman Sep 12, 2016
cf29a2e
Updated version for release.
danielputerman Sep 12, 2016
494c492
[maven-release-plugin] prepare release applitools-eyes-1.2
danielputerman Sep 12, 2016
9a9f618
Updated .gitignore .
danielputerman Sep 12, 2016
620861f
Updated "scm" tag in POM.
danielputerman Sep 12, 2016
319b2b8
POM Fixed version for release.
danielputerman Sep 12, 2016
6855dd5
[maven-release-plugin] prepare release applitools-eyes-1.2
danielputerman Sep 12, 2016
77e1444
[maven-release-plugin] prepare for next development iteration
danielputerman Sep 12, 2016
1224179
[maven-release-plugin] prepare release applitools-eyes-1.3
danielputerman Sep 12, 2016
2a3484f
[maven-release-plugin] prepare for next development iteration
danielputerman Sep 12, 2016
03bbbcd
Updated Applitools iframe height (now taller).
danielputerman Sep 14, 2016
ff4db99
[maven-release-plugin] prepare release applitools-eyes-1.4
danielputerman Sep 14, 2016
f913cc0
[maven-release-plugin] prepare for next development iteration
danielputerman Sep 14, 2016
003dafa
Added APPLITOOLS_BATCH_NAME environment variable.
danielputerman Feb 2, 2017
d685930
Updated inline documentation.
danielputerman Feb 2, 2017
9b2f18f
[maven-release-plugin] prepare release applitools-eyes-1.5
danielputerman Feb 2, 2017
3a3e624
[maven-release-plugin] prepare for next development iteration
danielputerman Feb 2, 2017
f1c04b9
pipeline-support
addihorowitz Jun 1, 2017
c88f818
bug fixes
addihorowitz Jun 6, 2017
93ebfff
Merge branch 'master' into pipeline-support
Jun 6, 2017
e234657
add missing files
addihorowitz Jun 6, 2017
2732990
add missing changes
addihorowitz Jun 6, 2017
2372f8b
Merge branch 'pipeline-support' of https://github.com/addihorowitz/ey…
addihorowitz Jun 6, 2017
3b2caaf
revert changes to README
addihorowitz Jun 7, 2017
3a86869
Merge pull request #1 from addihorowitz/pipeline-support
danielputerman Jun 25, 2017
ed4e34c
[maven-release-plugin] prepare release applitools-eyes-1.6
danielputerman Jul 19, 2017
81e18a0
[maven-release-plugin] prepare for next development iteration
danielputerman Jul 19, 2017
8c79362
getDisplayName() instead of getName()
Nov 16, 2018
3071d92
Merge pull request #2 from nikita-andreev/185-jenkins-bug
danielputerman Jan 17, 2019
b86b1a2
inline documentation
danielputerman Jan 17, 2019
ca00e58
fix jenkins repo to use https
danielputerman Jan 20, 2019
7d37e85
[maven-release-plugin] prepare release applitools-eyes-1.7
danielputerman Jan 23, 2019
32a0715
[maven-release-plugin] prepare for next development iteration
danielputerman Jan 23, 2019
71f403d
APPLITOOLS_SEQUENCE_NAME env var
Jun 18, 2019
16e47da
APPLITOOLS_SEQUENCE_NAME is implemented
Jun 18, 2019
030dd58
Merge pull request #3 from nikita-andreev/master
danielputerman Jul 17, 2019
64f956a
[maven-release-plugin] prepare release applitools-eyes-1.8
danielputerman Jul 17, 2019
6a84069
[maven-release-plugin] prepare for next development iteration
danielputerman Jul 17, 2019
9e2636e
Job DSL extension: wrappers { Applitools('http://your.server') }
Jul 26, 2019
d54cb83
Merge remote-tracking branch 'origin/master' into job_dsl
Jul 26, 2019
17c0f3a
Merge pull request #1 from nikita-andreev/job_dsl
nikita-andreev Jul 26, 2019
9b1b16d
POM.xml fixes
Jul 26, 2019
ed5219c
Merge pull request #2 from nikita-andreev/job_dsl
nikita-andreev Jul 26, 2019
4eb98d1
APPLITOOLS_BATCH_SEQUENCE environment variable
Jul 29, 2019
fac88a8
Merge pull request #3 from nikita-andreev/job_dsl
nikita-andreev Jul 29, 2019
7b0da9b
APPLITOOLS_BATCH_SEQUENCE environment variable
Jul 29, 2019
0a85631
Merge pull request #4 from nikita-andreev/job_dsl
nikita-andreev Jul 29, 2019
3dee6a2
Merge pull request #5 from nikita-andreev/master
danielputerman Jul 29, 2019
81d00a6
Method naming fixes
Jul 29, 2019
39919d5
Merge pull request #5 from nikita-andreev/job_dsl
nikita-andreev Jul 29, 2019
4c10b33
Merge pull request #6 from nikita-andreev/master
danielputerman Jul 30, 2019
03a4e95
[maven-release-plugin] prepare for next development iteration
danielputerman Jul 30, 2019
fab1e5a
[maven-release-plugin] prepare release applitools-eyes-1.10
danielputerman Jul 31, 2019
abad748
[maven-release-plugin] prepare for next development iteration
danielputerman Jul 31, 2019
9ab675f
Very first implementation of the closeBatch call after the build
Oct 16, 2019
093304f
Close Batch implementation
Oct 18, 2019
36155d8
Applitools pipeline step bartchClose implementation
Oct 25, 2019
3cfbd75
apiAccess renamed to applitoolsApiKey
Oct 25, 2019
0591d6d
Merge pull request #7 from nikita-andreev/batch_notification
danielputerman Nov 14, 2019
b8d7e9b
Added CHANGELOG.md
danielputerman Nov 14, 2019
d521069
.gitignore - added jenv related file
danielputerman Nov 18, 2019
28a1d57
[maven-release-plugin] prepare for next development iteration
danielputerman Nov 21, 2019
ba79599
RFE Trello 1598 Override Batch ID (#8)
nikita-andreev May 31, 2020
998c5ca
reverted version number to correct status
danielputerman May 31, 2020
295ba4f
Fixes due to Jenkins automatic tests.
danielputerman Jul 10, 2020
d9d61e3
CHANGELOG.md
danielputerman Jul 10, 2020
bf22f85
[maven-release-plugin] prepare release applitools-eyes-1.12
danielputerman Jul 10, 2020
bcb7697
[maven-release-plugin] prepare for next development iteration
danielputerman Jul 10, 2020
711cf5b
Updated README.
danielputerman Jul 10, 2020
213c6c3
added agent ID to iframe link.
danielputerman Dec 24, 2020
2f9de53
[maven-release-plugin] prepare release applitools-eyes-1.13
danielputerman Jan 13, 2021
1da1d23
[maven-release-plugin] prepare for next development iteration
danielputerman Jan 13, 2021
2236c73
introduce isCustomBatchId to check if using custom batch id when arch…
IdosApplitools Dec 4, 2022
8ce7e1e
update jenkins.version + parent pom + JobDSL + use Jenkins core BOM f…
IdosApplitools Dec 4, 2022
a86641d
remove unused print
IdosApplitools Dec 4, 2022
3644895
update CHANGELOG
IdosApplitools Dec 4, 2022
a637aae
update version and use other method for REST communication
itaibh Feb 22, 2023
a3f6e68
Merge pull request #11 from jenkinsci/bugfix_trell_1036_newer_jenkins
itaibh Feb 27, 2023
cda2396
Update CHANGELOG.md
itaibh Feb 27, 2023
4673f27
Update CHANGELOG.md
itaibh Feb 27, 2023
cc42d28
Merge branch 'master' into trello_bugfix_2201_missing_custom_batch_id
itaibh Mar 14, 2023
a06aa2b
Merge pull request #10 from jenkinsci/trello_bugfix_2201_missing_cust…
itaibh Mar 14, 2023
d152803
Merge branch 'master' into idos/trello_bugfix_2201_missing_custom_bat…
itaibh Mar 14, 2023
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ target/
*.iml
*~
.DS_Store
work/
work/
*.releaseBackup
release.properties
/.java-version
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [vNext] - dNext
### Updated
- Check if using a custom batch id before archiving it. [Trello 2201](https://trello.com/c/B8KrpLpF)
- Update `jenkins.version` to version `2.361.4` as [recommended here](https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/).
- Update parent pom to `4.51`.
- Remove deprecated `java.level` property.
- Bump JobDSL to `1.72` to rely on non-vulnerable version.
- Rely on Jenkins core BOM for workflow plugins versions.

## [1.14] - 2023-02-27
### Fixed
- Fixed crash on newer Jenkins versions.

## [1.12] - 2019-11-13
### Added
- Allow setting Batch ID explicitly.

## [1.11] - 2019-11-13
### Added
- This CHANGELOG file.
- Batch close & notification support.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## Depracated
## Applitools Eyes Plugin for Jenkins
----------

This project contains the original source code for the Applitools Eyes Jenkins/Hudson plugin. You should use the Jenkins fork instead: https://github.com/jenkinsci/applitools-eyes-plugin
### Usage

#### Adding the Applitools Eyes plugin to your Jenkins CI:
To install built package to your Jenkins, use menu Jenkins => Manage Jenkins => Manage Plugins. On the 'Advanced' tab download the applitools-eye.jar
For more details see the [guide](https://www.jenkins.io/doc/book/managing/plugins/)

#### Adding Applitools to your project
The Applitools support is available on project basis. To enable Applitools support for a project, check the 'Applitools support' on the **build environment** section on the projects' configuration page. [More details are available here](https://plugins.jenkins.io/applitools-eyes/)

#### Explicitly setting the BATCH ID / Name
The plugin exports a set of environment variables which are used by the Applitools SDK when a test is run,
and later by the plugin itself to present the Applitools results in the build status page.

These environment variables can overridden during the build.
For example, to override the APPLITOOLS_BATCH_ID environment variable, place a value to the file ./.applitools/BATCH_ID (in the build root folder).
If the file ./.applitools/BATCH_ID exists, the module will read it and export its value as APPLITOOLS_BATCH_ID environment variable.
Also, it will be stored as a build artifact, which will later be will be used to display the Applitools test results.

The same goes for any other Applitools environment variable.

#### Building the plugin from source

To build the version, execute

mvn clean; mvn package

The built module appears in the file://./target/applitools-eyes.jar
69 changes: 52 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.14</version>
<relativePath/>
<version>4.51</version>
<relativePath />
</parent>
<artifactId>applitools-eyes</artifactId>
<version>1.1</version>
<version>1.14-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Applitools Eyes Plugin</name>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Applitools+Eyes+Plugin</url>
Expand All @@ -22,21 +21,19 @@
</license>
</licenses>

<!-- Should be updated once in forked in the Jenkins repo -->
<!-- Should be updated once in forked in the Jenkins repo
<scm>
<connection>scm:git:git://github.com/jenkinsci/eyes.jenkins.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>applitools-eyes-1.1</tag>
<connection>scm:git:git://github.com/jenkinsci/applitools-eyes-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/applitools-eyes-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/applitools-eyes-plugin</url>
<tag>HEAD</tag>
</scm>
-->

<properties>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>1.625.3</jenkins.version>
<!-- Java Level to use. Java 7 required when using core >= 1.612 -->
<java.level>7</java.level>
<!-- Recommended version: https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.version>2.361.4</jenkins.version>
<!-- <= 1.71 vulnerable: https://www.jenkins.io/security/advisory/2019-03-06/#SECURITY-1342 -->
<plugins.job-dsl.version>1.72</plugins.job-dsl.version>
</properties>

<developers>
Expand All @@ -47,6 +44,45 @@
</developer>
</developers>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.303.x</artifactId>
<version>1409.v7659b_c072f18</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>${plugins.job-dsl.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness-htmlunit</artifactId>
<version>2.18-1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
Expand All @@ -59,5 +95,4 @@
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.applitools.jenkins;

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

/**
* Created by addihorowitz on 8/11/16.
* Base class for Applitools status display action.
*/
public abstract class AbstractApplitoolsStatusDisplayAction implements Action {

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

public abstract AbstractBuild<?, ?> getBuild();
}
130 changes: 78 additions & 52 deletions src/main/java/com/applitools/jenkins/ApplitoolsBuildWrapper.java
Original file line number Diff line number Diff line change
@@ -1,103 +1,128 @@
package com.applitools.jenkins;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.*;
import hudson.tasks.BuildWrapper;
import jenkins.util.VirtualFile;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.io.Serializable;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import hudson.util.FormValidation;
import hudson.model.JobProperty;
import org.kohsuke.stapler.QueryParameter;

import java.net.URL;
import java.util.regex.Matcher;

/**
* Created by addihorowitz on 8/28/16.
* Code for the build page.
*/

public class ApplitoolsBuildWrapper extends BuildWrapper implements Serializable {
public String serverURL = DescriptorImpl.APPLITOOLS_DEFAULT_URL;
public final static String BATCH_NOTIFICATION_PATH = "/api/sessions/batches/%s/close/bypointerid";
public String serverURL;
public boolean notifyByCompletion;
public String applitoolsApiKey;

private static boolean isCustomBatchId = false;

static final Map<String, String> ARTIFACT_PATHS = new HashMap();

static {
ARTIFACT_PATHS.put(
ApplitoolsCommon.APPLITOOLS_ARTIFACT_PREFIX +
"_" +
ApplitoolsEnvironmentUtil.APPLITOOLS_BATCH_ID,
ApplitoolsCommon.APPLITOOLS_ARTIFACT_FOLDER +
"/" +
ApplitoolsEnvironmentUtil.APPLITOOLS_BATCH_ID
);
}

@DataBoundConstructor
public ApplitoolsBuildWrapper(String serverURL) {
public ApplitoolsBuildWrapper(String serverURL, boolean notifyByCompletion, String applitoolsApiKey) {
this.applitoolsApiKey = applitoolsApiKey;
this.notifyByCompletion = notifyByCompletion;
if (serverURL != null && !serverURL.isEmpty())
{
if (DescriptorImpl.validURL(serverURL))
{
this.serverURL = serverURL.trim();
}
} else {
this.serverURL = DescriptorImpl.APPLITOOLS_DEFAULT_URL;
this.serverURL = ApplitoolsCommon.APPLITOOLS_DEFAULT_URL;
}
}

@Override
public Environment setUp(final AbstractBuild build, Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
public Environment setUp(final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {

runPreBuildActions(build, listener);

return new Environment() {
@Override
public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
if (isCustomBatchId) {
build.pickArtifactManager().archive(build.getWorkspace(), launcher, listener, ARTIFACT_PATHS);
}
ApplitoolsCommon.closeBatch(build, listener, serverURL, notifyByCompletion, applitoolsApiKey);
return true;
}

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

private void runPreBuildActions(final AbstractBuild 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();

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());
ApplitoolsEnvironmentUtil.outputVariables(listener, env, serverURL, 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;
public static Map<String, String> getApplitoolsArtifactList(AbstractBuild build, TaskListener listener) {
Map<String, String> applitoolsArtifacts = new HashMap();
FilePath workspace = build.getWorkspace();
if (workspace != null) {
VirtualFile rootDir = workspace.toVirtualFile();
for (Map.Entry<String, String> apath : ARTIFACT_PATHS.entrySet()) {
try {
InputStream stream = rootDir.child(apath.getValue()).open();
String value = IOUtils.toString(stream, StandardCharsets.UTF_8.name()).replaceAll(System.getProperty("line.separator"), "");
Matcher m = ApplitoolsCommon.artifactRegexp.matcher(apath.getKey());
if (m.find()) {
applitoolsArtifacts.put(m.group(1), value);
isCustomBatchId = true;
}
} catch (IOException e) {
isCustomBatchId = false;
listener.getLogger().println(String.format("Custom BATCH_ID is not defined: %s", rootDir.child(apath.getValue())));
}
}
} else {
listener.getLogger().println("build.getWorkspace() returned null, skipping check for applitools artifacts.");
}
if (!found)
{
JobProperty jp = new ApplitoolsProjectConfigProperty(this.serverURL);
build.getProject().addProperty(jp);
}
build.getProject().save();
return applitoolsArtifacts;
}

private void addApplitoolsActionToBuild(final AbstractBuild build)
private void runPreBuildActions(final Run build, final BuildListener listener) throws IOException, InterruptedException
{
ApplitoolsStatusDisplayAction buildAction = build.getAction(ApplitoolsStatusDisplayAction.class);
if (buildAction == null) {
buildAction = new ApplitoolsStatusDisplayAction(build);
build.addAction(buildAction);
}
listener.getLogger().println("Starting Applitools Eyes pre-build (server URL is '" + this.serverURL + "') apiKey is " + this.applitoolsApiKey);

ApplitoolsCommon.integrateWithApplitools(build, this.serverURL, this.notifyByCompletion, this.applitoolsApiKey);

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

@Extension
public static final class DescriptorImpl extends Descriptor<BuildWrapper> {
public static final String APPLITOOLS_DEFAULT_URL = "https://eyes.applitools.com";
public static String APPLITOOLS_DEFAULT_URL="https://eyes.applitools.com";
public static boolean NOTIFY_BY_COMPLETION=true;

public DescriptorImpl() {
load();
}
Expand All @@ -109,8 +134,9 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {

protected static boolean validURL(String url)
{
// Just making sure the URL is valid.
try {
URL serverURL = new URL(url);
new URL(url);
} catch (Exception ex) {
return false;
}
Expand Down Expand Up @@ -138,7 +164,7 @@ public String getDisplayName() {

@Override
public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) throws Descriptor.FormException {
return new ApplitoolsBuildWrapper(formData.getString("serverURL"));
return new ApplitoolsBuildWrapper(formData.getString("serverURL"), formData.getBoolean("notifyByCompletion"), formData.getString("applitoolsApiKey"));
}
}
}
Expand Down
Loading