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 #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ target/
inject-tests/
test-output
*~
.idea
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
<dependency>
<groupId>br.eti.kinoshita</groupId>
<artifactId>testlink-java-api</artifactId>
<version>1.9.14-0</version>
<version>1.9.14-1-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for using 1.9.14-1-SNAPSHOT? Which version of TestLink did you test your code against, please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind the reason for using the snapshot. Probably you were using your local version with the buildCustomFields.

</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down Expand Up @@ -306,6 +306,11 @@
<artifactId>junit</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.1</version>
</dependency>
</dependencies>

<repositories>
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class AbstractTestLinkBuilder extends Builder {
* The name of the Build.
*/
protected String buildName;
/**
* The Build custom fields.
*/
protected String buildCustomFields;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we merge that other pull request from testlink-java-api, we can merge this PR too.

/**
* The platform name.
*/
Expand Down Expand Up @@ -133,7 +137,7 @@ public class AbstractTestLinkBuilder extends Builder {
* Create a AbstractTestLinkBuilder.
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, String testPlanCustomFields, List<BuildStep> singleBuildSteps,
String platformName, String buildName, String buildCustomFields, String customFields, String testPlanCustomFields, List<BuildStep> singleBuildSteps,
List<BuildStep> beforeIteratingAllTestCasesBuildSteps, List<BuildStep> iterativeBuildSteps,
List<BuildStep> afterIteratingAllTestCasesBuildSteps, Boolean transactional,
Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults, Boolean failOnNotRun,
Expand All @@ -144,6 +148,7 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
this.testPlanName = testPlanName;
this.platformName = platformName;
this.buildName = buildName;
this.buildCustomFields = buildCustomFields;
this.customFields = customFields;
this.testPlanCustomFields = testPlanCustomFields;
this.singleBuildSteps = singleBuildSteps;
Expand All @@ -162,12 +167,12 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @deprecated to add test plan custom fields
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, List<BuildStep> singleBuildSteps,
String platformName, String buildName, String buildCustomFields, String customFields, List<BuildStep> singleBuildSteps,
List<BuildStep> beforeIteratingAllTestCasesBuildSteps, List<BuildStep> iterativeBuildSteps,
List<BuildStep> afterIteratingAllTestCasesBuildSteps, Boolean transactional,
Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults, Boolean failOnNotRun,
List<ResultSeeker> resultSeekers) {
this(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields,
this(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields, customFields,
/*testPlanCustomFields*/ null, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps,
iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
Expand All @@ -181,8 +186,8 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @param testPlanName TestLink Test Plan name.
* @param platformName TestLink Platform name.
* @param buildName TestLink Build name.
* @param buildCustomFields TestLink Build custom fields.
* @param customFields TestLink comma-separated list of Custom Fields.
* @param keyCustomField Key custom field.
* @param singleBuildSteps List of build steps to execute once for all automated test cases.
* @param beforeIteratingAllTestCasesBuildSteps Command executed before iterating all test cases.
* @param iterativeBuildSteps List of build steps to execute for each Automated Test Case.
Expand All @@ -194,13 +199,13 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @deprecated
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, Boolean executionStatusNotRun,
String platformName, String buildName, String buildCustomFields, String customFields, Boolean executionStatusNotRun,
Boolean executionStatusPassed, Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps, List<BuildStep> beforeIteratingAllTestCasesBuildSteps,
List<BuildStep> iterativeBuildSteps, List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults,
Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
this(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields,
this(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields, customFields,
/*testPlanCustomFields*/ null, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps,
iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
Expand All @@ -226,6 +231,8 @@ public String getBuildName() {
return this.buildName;
}

public String getBuildCustomFields() { return this.buildCustomFields; }

public String getCustomFields() {
return this.customFields;
}
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/hudson/plugins/testlink/TestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -90,7 +91,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, List<ResultSeeker> resultSeekers) {
this(testLinkName, testProjectName, testPlanName, buildName,
this(testLinkName, testProjectName, testPlanName, buildName, null,
null, customFields, executionStatusNotRun, executionStatusPassed,
executionStatusFailed, executionStatusBlocked, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
Expand All @@ -112,7 +113,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, buildName, null,
super(testLinkName, testProjectName, testPlanName, buildName, null, null,
customFields, executionStatusNotRun, executionStatusPassed,
executionStatusFailed, executionStatusBlocked, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
Expand All @@ -125,7 +126,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
* @deprecated to add test plan custom fields
*/
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String platformName, String buildName, String customFields,
String testPlanName, String platformName, String buildName, String buildCustomFields, String customFields,
Boolean executionStatusNotRun, Boolean executionStatusPassed,
Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps,
Expand All @@ -134,15 +135,16 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, platformName, buildName,
super(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields,
customFields, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
}

@DataBoundConstructor
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String platformName, String buildName, String customFields, String testPlanCustomFields,
String testPlanName, String platformName, String buildName,
String buildCustomFields, String customFields, String testPlanCustomFields,
Boolean executionStatusNotRun, Boolean executionStatusPassed,
Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps,
Expand All @@ -151,7 +153,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, platformName, buildName,
super(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields,
customFields, testPlanCustomFields, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
Expand Down Expand Up @@ -194,16 +196,19 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
build.getEnvironment(listener), getPlatformName());
final String buildName = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getBuildName());
final String buildCustomFields = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getBuildCustomFields());
final String buildNotes = Messages.TestLinkBuilder_Build_Notes();
if(LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "TestLink project name: ["+testProjectName+"]");
LOGGER.log(Level.FINE, "TestLink plan name: ["+testPlanName+"]");
LOGGER.log(Level.FINE, "TestLink platform name: ["+platformName+"]");
LOGGER.log(Level.FINE, "TestLink build name: ["+buildName+"]");
LOGGER.log(Level.FINE, "TestLink build notes: ["+buildNotes+"]");
LOGGER.log(Level.FINE, "TestLink build Custom Fields: ["+buildCustomFields+"]");
}
// TestLink Site object
testLinkSite = this.getTestLinkSite(testLinkUrl, testLinkDevKey, testProjectName, testPlanName, platformName, buildName, buildNotes);
testLinkSite = this.getTestLinkSite(testLinkUrl, testLinkDevKey, testProjectName, testPlanName, platformName, buildName, buildCustomFields, buildNotes);

if (StringUtils.isNotBlank(platformName) && testLinkSite.getPlatform() == null)
listener.getLogger().println(Messages.TestLinkBuilder_PlatformNotFound(platformName));
Expand Down Expand Up @@ -257,7 +262,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
if(getResultSeekers() != null) {
for (ResultSeeker resultSeeker : getResultSeekers()) {
LOGGER.log(Level.INFO, "Seeking test results. Using: " + resultSeeker.getDescriptor().getDisplayName());
resultSeeker.seek(automatedTestCases, build, launcher, listener, testLinkSite);
resultSeeker.seek(automatedTestCases, build, build.getWorkspace(), launcher, listener, testLinkSite);
}
}
} catch (ResultSeekerException trse) {
Expand Down Expand Up @@ -325,7 +330,7 @@ private TestCaseWrapper[] transform(TestCase[] testCases) {
*/
public TestLinkSite getTestLinkSite(String testLinkUrl, String testLinkDevKey,
String testProjectName, String testPlanName, String platformName,
String buildName, String buildNotes) throws MalformedURLException {
String buildName, String buildCustomFields, String buildNotes) throws MalformedURLException {
final TestLinkAPI api;
final URL url = new URL(testLinkUrl);
api = new TestLinkAPI(url, testLinkDevKey);
Expand All @@ -344,7 +349,17 @@ public TestLinkSite getTestLinkSite(String testLinkUrl, String testLinkDevKey,
}
}

/* Extract custom fields and values */
java.util.Map<String, String> cfs = new HashMap<String, String>();
for (String part: buildCustomFields.split(",")) {
String[] cf = part.split(":");
String name = cf[0].replaceAll("\\s+", "");
String value = cf[1].replaceAll("\\s+", "");
cfs.put(name, value);
}

final Build build = api.createBuild(testPlan.getId(), buildName, buildNotes);
api.updateBuildCustomFields(build.getId(), testProject.getId(), testPlan.getId(), cfs);
return new TestLinkSite(api, testProject, testPlan, platform, build);
}

Expand Down
Loading