Package com.perforce.halm.jenkins
Class HALMTestReporterCommon
- java.lang.Object
-
- com.perforce.halm.jenkins.HALMTestReporterCommon
-
public class HALMTestReporterCommon extends Object
Class for common field operations for HALMTestReporterDescriptor and HALMTestReporterStep.
-
-
Constructor Summary
Constructors Constructor Description HALMTestReporterCommon()
Initializes a Logger for the class calling this.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
determineOS(Platform p)
Determines the OS with the supplied Platform enum.FormValidation
doAutomationSuiteIDValidation(String value)
Checks if an automation suite has been selected.ListBoxModel
doFillAutomationSuiteIDItems(String halmConnectionID, String projectID)
Populates the Automation Suite dropdown based on the selected connection and project.ListBoxModel
doFillHalmConnectionIDItems()
Populates the 'credentialType' dropdown with appropriate values.ListBoxModel
doFillProjectIDItems(String halmConnectionID)
Populates the 'projectID' dropdown based on the selection of the connectionID dropdown.ListBoxModel
doFillTestFileFormatItems()
Populates the Test File Format dropdown.ListBoxModel
doFillTestRunSetIDItems(String halmConnectionID, String projectID)
Populates the Test Run Set dropdown.FormValidation
doHalmConnectionIDValidation(String value)
Checks the validity of the current connection.FormValidation
doProjectIDValidation(String value)
Checks if a Helix ALM project has been selected.static com.perforce.halm.rest.ConnectionInfo
getConnectionInfo(@NotNull HALMConnection connection)
Gets the connection info from a selected connection.static com.cloudbees.plugins.credentials.common.StandardCredentials
getCredentialsFromConnection(@NotNull HALMConnection connection)
Retrieves the credentials based on the Helix ALM connectionstatic com.cloudbees.plugins.credentials.common.StandardCredentials
getCredentialsFromId(String credentialsID)
Retrieves the credentials based on a credential IDstatic String
getExceptionForLogging(Exception ex)
Converts the exception into a stack trace we can log.String
getIDOfAutomationSuite(String name, String connID, String projID)
Gets the id (or key) of the first automation suite with the given name, or null if nothing existsString
getIDOfTestRunSet(String name, String connID, String projID)
Gets the id (or key) of the first test run set with the given name, or null if nothing existsString
getLabelOfAutomationSuite(long id)
Gets the label (or name) of an automation suite given its ID, or null if nothing exists.static String
getLabelOfTestRunSet(long id)
Gets the label of a test run set given its ID, or null if nothing exists.static com.perforce.halm.reportingtool.format.ReportFormatType
getTypeFromOrdinal(String ord)
From the ordinal expressed as a string, get the ReportFormatType enum with that ordinal.void
logFromCaller(String message)
Writes a message to log from its caller.void
setLastProjectID(String projectID)
void
submitBuildToHelixALM(@NotNull Run<?,?> run, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, HALMTestReporterObject reportObj)
Common function to submit test results to Helix ALM.
-
-
-
Method Detail
-
getExceptionForLogging
public static String getExceptionForLogging(Exception ex)
Converts the exception into a stack trace we can log.- Parameters:
ex
- Exception we want to log- Returns:
- String containing the stack trace of the error.
-
setLastProjectID
public void setLastProjectID(String projectID)
-
doHalmConnectionIDValidation
public FormValidation doHalmConnectionIDValidation(String value)
Checks the validity of the current connection.- Returns:
- Whether the connection is valid (can we connect at all?)
-
doProjectIDValidation
public FormValidation doProjectIDValidation(String value)
Checks if a Helix ALM project has been selected. Should not be able to select a project that does not exist.- Returns:
- FormValidation.error if the project is somehow empty, OK otherwise
-
doAutomationSuiteIDValidation
public FormValidation doAutomationSuiteIDValidation(String value)
Checks if an automation suite has been selected. Should not be possible to get a suite that does not exist.- Returns:
- FormValidation.error if the suite is somehow empty, OK otherwise
-
doFillHalmConnectionIDItems
public ListBoxModel doFillHalmConnectionIDItems()
Populates the 'credentialType' dropdown with appropriate values.- Returns:
- Credential Type dropdown list values.
-
doFillProjectIDItems
public ListBoxModel doFillProjectIDItems(String halmConnectionID)
Populates the 'projectID' dropdown based on the selection of the connectionID dropdown.- Parameters:
halmConnectionID
- Currently selected halmConnectionID- Returns:
- Populated list of entries for the projectID dropdown.
-
doFillAutomationSuiteIDItems
public ListBoxModel doFillAutomationSuiteIDItems(String halmConnectionID, String projectID)
Populates the Automation Suite dropdown based on the selected connection and project.- Parameters:
halmConnectionID
- Currently selected HALM Connection UUIDprojectID
- Currently selected HALM Project UUID- Returns:
- Populated list of entries for the automationSuiteName dropdown
-
doFillTestFileFormatItems
public ListBoxModel doFillTestFileFormatItems()
Populates the Test File Format dropdown.- Returns:
- Populated list of entries for the testFileFormat dropdown.
-
doFillTestRunSetIDItems
public ListBoxModel doFillTestRunSetIDItems(String halmConnectionID, String projectID)
Populates the Test Run Set dropdown.- Parameters:
halmConnectionID
- Currently selected HALM Connection UUIDprojectID
- Currently selected HALM Project UUID- Returns:
- Populated list of entries for the testRunSet dropdown
-
getCredentialsFromId
public static com.cloudbees.plugins.credentials.common.StandardCredentials getCredentialsFromId(String credentialsID)
Retrieves the credentials based on a credential ID- Parameters:
credentialsID
- Jenkins credentials ID- Returns:
- Jenkins credentials, or null if no credentials could be found.
-
getCredentialsFromConnection
public static com.cloudbees.plugins.credentials.common.StandardCredentials getCredentialsFromConnection(@NotNull @NotNull HALMConnection connection)
Retrieves the credentials based on the Helix ALM connection- Parameters:
connection
- Helix ALM connection- Returns:
- Jenkins Credentials, or null if no credentials could be found.
-
getTypeFromOrdinal
public static com.perforce.halm.reportingtool.format.ReportFormatType getTypeFromOrdinal(String ord)
From the ordinal expressed as a string, get the ReportFormatType enum with that ordinal.- Parameters:
ord
- - the ordinal as it is in the list box.- Returns:
- - the enum, or null if we somehow got a bad ordinal
-
determineOS
public static String determineOS(Platform p)
Determines the OS with the supplied Platform enum.- Parameters:
p
- - the Platform from the environment, will be WINDOWS or UNIX- Returns:
- A string representing the operating system the tests were run on.
-
getConnectionInfo
public static com.perforce.halm.rest.ConnectionInfo getConnectionInfo(@NotNull @NotNull HALMConnection connection) throws Exception
Gets the connection info from a selected connection. This is a public function so that its callers can use it as needed.- Parameters:
connection
- - the selected HALMConnection- Returns:
- the connectionInfo for the HALMConnection.
- Throws:
Exception
- if anything fails.
-
getLabelOfAutomationSuite
public String getLabelOfAutomationSuite(long id)
Gets the label (or name) of an automation suite given its ID, or null if nothing exists. WARNING: The cache doesn't work for pipelines; you will always get null due to how pipelines work.- Parameters:
id
- - The id of the automation suite returned from the REST API.- Returns:
- The suite's name from cache.
-
getLabelOfTestRunSet
public static String getLabelOfTestRunSet(long id)
Gets the label of a test run set given its ID, or null if nothing exists. WARNING: The cache doesn't work for pipelines; you will always get null due to how pipelines work.- Parameters:
id
- - the id of the test run set returned from the REST API.- Returns:
- The set's name from cache.
-
getIDOfAutomationSuite
public String getIDOfAutomationSuite(String name, String connID, String projID)
Gets the id (or key) of the first automation suite with the given name, or null if nothing exists- Parameters:
name
- - The name of the automation suite returned from the REST API.connID
- - the connection IDprojID
- - the Helix ALM project ID- Returns:
- the suite's ID from cache.
-
getIDOfTestRunSet
public String getIDOfTestRunSet(String name, String connID, String projID)
Gets the id (or key) of the first test run set with the given name, or null if nothing exists- Parameters:
name
- - The name of the automation suite returned from the REST API.connID
- - the connection IDprojID
- - the Helix ALM project ID- Returns:
- the suite's ID from cache.
-
logFromCaller
public void logFromCaller(String message)
Writes a message to log from its caller.- Parameters:
message
- - The message to write to log.
-
submitBuildToHelixALM
public void submitBuildToHelixALM(@NotNull @NotNull Run<?,?> run, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, HALMTestReporterObject reportObj) throws Exception
Common function to submit test results to Helix ALM.- Parameters:
run
- - The Jenkins build that called this function.workspace
- - The workspace generated by the build. If null, default to the first "root" of the jenkins server.env
- - The environment that the build runs with.launcher
- - The launcher object generated by a build.listener
- - the logger for the run object. If null, write to this object's log instead.reportObj
- - The report object, supplied by the caller.- Throws:
Exception
- - if anything goes wrong aside from what is expected, return the function to the caller.
-
-