From 4494f261c7106b7380ac11f3fd6c272694f8c515 Mon Sep 17 00:00:00 2001 From: Bohdan Bokhonko Date: Mon, 16 Jan 2023 23:34:44 +0200 Subject: [PATCH 1/4] US: #2029018 Send custom properties to ALM Octane on Job completion --- .../AbstractBuildListenerOctaneImpl.java | 5 +- .../OutputExecutionParametersHelper.java | 71 ++++++++++++++++++ .../tools/settings/OctaneBuildWrapper.java | 74 +++++++++++++++++++ ...RunnerMiscSettingsGlobalConfiguration.java | 18 ++++- .../settings/OctaneBuildWrapper/config.jelly | 34 +++++++++ .../help-outputExecutionParameters.html | 33 +++++++++ .../config.jelly | 3 + .../help-outputExecutionParameters.html | 31 ++++++++ .../help/help-octaneBuildEnvConfig.html | 31 ++++++++ 9 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java create mode 100644 src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java create mode 100644 src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly create mode 100644 src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html create mode 100644 src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html create mode 100644 src/main/webapp/help/help-octaneBuildEnvConfig.html diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java index 0ba1b8bc98..0233786875 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java @@ -55,6 +55,8 @@ import java.util.List; +import static com.microfocus.application.automation.tools.octane.events.OutputExecutionParametersHelper.getOutputExecutionParams; + /** * Run Listener that handles basic CI events and dispatches notifications to the Octane server * User: gullery @@ -126,7 +128,8 @@ private void publishFinishEvent(AbstractBuild build) { .setParameters(ParameterProcessors.getInstances(build)) .setResult(BuildHandlerUtils.translateRunResult(build)) .setDuration(build.getDuration()) - .setTestResultExpected(hasTests); + .setTestResultExpected(hasTests) + .setCiExecutionParameters(getOutputExecutionParams(build)); CommonOriginRevision commonOriginRevision = getCommonOriginRevision(build); if (commonOriginRevision != null) { event diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java new file mode 100644 index 0000000000..2a748b76df --- /dev/null +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java @@ -0,0 +1,71 @@ +package com.microfocus.application.automation.tools.octane.events; + +import com.microfocus.application.automation.tools.settings.OctaneBuildWrapper; +import com.microfocus.application.automation.tools.settings.RunnerMiscSettingsGlobalConfiguration; +import com.microfocus.application.automation.tools.sse.common.StringUtils; +import hudson.EnvVars; +import hudson.model.AbstractBuild; +import hudson.model.BuildableItemWithBuildWrappers; +import hudson.model.Job; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OutputExecutionParametersHelper { + + private static final String SPLIT_SYMBOL = " "; + + public static Map getOutputExecutionParams(AbstractBuild build) { + EnvVars environment = getEnvironment(build); + if (environment == null) { + return Collections.emptyMap(); + } else { + List paramKeysList = getGlobalParamsList(); + paramKeysList.addAll(getJobParamsList(build)); + + if (paramKeysList.isEmpty()) return Collections.emptyMap(); + + Map outputExecutionParams = new HashMap<>(); + Set sensitiveBuildVariables = build.getSensitiveBuildVariables(); + + String value; + for (String key : paramKeysList) { + if (sensitiveBuildVariables.contains(key)) continue; + value = environment.get(key); + if (value != null) { + outputExecutionParams.put(key, value); + } + } + return outputExecutionParams; + } + } + + private static EnvVars getEnvironment(AbstractBuild build) { + EnvVars environment = null; + try { + environment = build.getEnvironment(null); + } catch (IOException | InterruptedException ignored) { + } + return environment; + } + + private static List getGlobalParamsList() { + return Stream.of(RunnerMiscSettingsGlobalConfiguration.getInstance().getOutputExecutionParameters().split(SPLIT_SYMBOL)) + .filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); + } + + private static List getJobParamsList(AbstractBuild build) { + Job job = build.getParent(); + if (job instanceof BuildableItemWithBuildWrappers) { + String paramsStr = ((BuildableItemWithBuildWrappers) job).getBuildWrappersList(). + get(OctaneBuildWrapper.class).getOutputExecutionParameters(); + if (paramsStr != null) { + String[] params = paramsStr.split(SPLIT_SYMBOL); + return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); + } + } + return Collections.emptyList(); + } +} diff --git a/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java b/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java new file mode 100644 index 0000000000..4f6d7be239 --- /dev/null +++ b/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java @@ -0,0 +1,74 @@ +package com.microfocus.application.automation.tools.settings; + +import com.microfocus.application.automation.tools.sse.common.StringUtils; +import hudson.EnvVars; +import hudson.Extension; +import hudson.Launcher; +import hudson.model.AbstractBuild; +import hudson.model.AbstractProject; +import hudson.model.BuildListener; +import hudson.tasks.BuildWrapper; +import hudson.tasks.BuildWrapperDescriptor; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OctaneBuildWrapper extends BuildWrapper implements Serializable { + + private String outputExecutionParameters; + @DataBoundConstructor + public OctaneBuildWrapper(String outputExecutionParameters) { + this.outputExecutionParameters = outputExecutionParameters; + } + + public String getOutputExecutionParameters() { + return outputExecutionParameters; + } + @DataBoundSetter + public void setOutputExecutionParameters(String outputExecutionParameters) { + this.outputExecutionParameters = getValidatedOutputExecutionParameters(outputExecutionParameters); + } + + @Override + public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { + EnvVars envVars = build.getEnvironment(listener); + return new Environment() { + @Override + public void buildEnvVars(Map env) { + env.putAll(envVars); + } + }; + } + + private String getValidatedOutputExecutionParameters(String executionParams) { + String[] params = executionParams.split(" "); + return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)) + .collect(Collectors.joining(" ")); + } + + + @Extension + public static final class DescriptorImpl extends BuildWrapperDescriptor { + + @Override + public boolean isApplicable(AbstractProject item) { + return true; + } + + @Override + public String getDisplayName() { + return "Octane Build Environment"; + } + + @Override + public String getHelpFile() { + return "/plugin/hp-application-automation-tools-plugin/help/help-octaneBuildEnvConfig.html"; + } + } + +} diff --git a/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java b/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java index aea7072dc9..5ff67db768 100644 --- a/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java +++ b/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java @@ -53,16 +53,19 @@ public class RunnerMiscSettingsGlobalConfiguration extends GlobalConfiguration i public static final List DEFAULT_UFT_DATE_PATTERNS = Arrays.asList(DEFAULT_UFT_DATE_PATTERN1, DEFAULT_UFT_DATE_PATTERN2, DEFAULT_UFT_DATE_PATTERN3); public static final String DEFAULT_BRANCHES = "master main trunk mainline"; + public static final String DEFAULT_OUTPUT_EXECUTION_PARAMETERS = "BUILD_DISPLAY_NAME BUILD_TAG BUILD_URL"; private String dateFormat; private String defaultBranches; + private String outputExecutionParameters; private boolean agentToControllerEnabled; @DataBoundConstructor - public RunnerMiscSettingsGlobalConfiguration(String mfDateFormat, String defaultBranches,boolean agentToControllerEnabled) { + public RunnerMiscSettingsGlobalConfiguration(String mfDateFormat, String defaultBranches, String outputExecutionParameters, boolean agentToControllerEnabled) { setDateFormat(mfDateFormat); setDefaultBranches(defaultBranches); setAgentToControllerEnabled(agentToControllerEnabled); + setOutputExecutionParameters(outputExecutionParameters); } public RunnerMiscSettingsGlobalConfiguration() { @@ -102,7 +105,14 @@ public void setDefaultBranches(String defaultBranches) { save(); } + public String getOutputExecutionParameters() { + return outputExecutionParameters; + } + public void setOutputExecutionParameters(String outputExecutionParameters) { + this.outputExecutionParameters = getValidatedOutputExecutionParameters(outputExecutionParameters); + save(); + } private String getValidatedDefaultBranches(String defaultBranches) { String[] branches = defaultBranches.split(" "); @@ -110,6 +120,12 @@ private String getValidatedDefaultBranches(String defaultBranches) { .collect(Collectors.joining(" ")); } + private String getValidatedOutputExecutionParameters(String executionParams) { + String[] props = executionParams.split(" "); + return Stream.of(props).filter(p -> !StringUtils.isNullOrEmpty(p)) + .collect(Collectors.joining(" ")); + } + public DateTimeFormatter getDateFormatter() { return dateFormat != null ? DateTimeFormatter.ofPattern(dateFormat) : DateTimeFormatter.ofPattern(DEFAULT_UFT_DATE_PATTERN1); } diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly new file mode 100644 index 0000000000..7169f56703 --- /dev/null +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html new file mode 100644 index 0000000000..9a4b84d46c --- /dev/null +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html @@ -0,0 +1,33 @@ + + +
+ Define properties of a specific job, additional to the properties specified in the global settings. After the build is complete, Jenkins will pass these properties to a respective auto action. +
+ Delimit multiple properties with a space. +
\ No newline at end of file diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly index 0d994ef257..3d6b3e5263 100644 --- a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly @@ -35,6 +35,9 @@ + + + diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html new file mode 100644 index 0000000000..2e23321eba --- /dev/null +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html @@ -0,0 +1,31 @@ + + +
+ General Output Execution Parameters, which are applied to all jobs. +
\ No newline at end of file diff --git a/src/main/webapp/help/help-octaneBuildEnvConfig.html b/src/main/webapp/help/help-octaneBuildEnvConfig.html new file mode 100644 index 0000000000..6926445e27 --- /dev/null +++ b/src/main/webapp/help/help-octaneBuildEnvConfig.html @@ -0,0 +1,31 @@ + + +
+ ALM Octane related Environment configuration +
\ No newline at end of file From 2a6247830ff40d634c27627b7213e8d30b443063 Mon Sep 17 00:00:00 2001 From: Bohdan Bokhonko Date: Thu, 19 Jan 2023 21:28:00 +0200 Subject: [PATCH 2/4] US: #2029018 Send custom properties to ALM Octane on Job completion (Refactoring) --- .../AbstractBuildListenerOctaneImpl.java | 4 +-- ...=> OutputEnvironmentParametersHelper.java} | 25 +++++++++------ .../tools/settings/OctaneBuildWrapper.java | 29 ++++++++--------- ...RunnerMiscSettingsGlobalConfiguration.java | 26 +++++++++------- .../settings/OctaneBuildWrapper/config.jelly | 4 +-- ... => help-outputEnvironmentParameters.html} | 4 +-- .../config.jelly | 4 +-- ... => help-outputEnvironmentParameters.html} | 4 ++- .../help/help-octaneBuildEnvConfig.html | 31 ------------------- 9 files changed, 53 insertions(+), 78 deletions(-) rename src/main/java/com/microfocus/application/automation/tools/octane/events/{OutputExecutionParametersHelper.java => OutputEnvironmentParametersHelper.java} (70%) rename src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/{help-outputExecutionParameters.html => help-outputEnvironmentParameters.html} (86%) rename src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/{help-outputExecutionParameters.html => help-outputEnvironmentParameters.html} (83%) delete mode 100644 src/main/webapp/help/help-octaneBuildEnvConfig.html diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java index 0233786875..0b3e119222 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java @@ -55,7 +55,7 @@ import java.util.List; -import static com.microfocus.application.automation.tools.octane.events.OutputExecutionParametersHelper.getOutputExecutionParams; +import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.getOutputEnvironmentParams; /** * Run Listener that handles basic CI events and dispatches notifications to the Octane server @@ -129,7 +129,7 @@ private void publishFinishEvent(AbstractBuild build) { .setResult(BuildHandlerUtils.translateRunResult(build)) .setDuration(build.getDuration()) .setTestResultExpected(hasTests) - .setCiExecutionParameters(getOutputExecutionParams(build)); + .setEnvironmentOutputtedParameters(getOutputEnvironmentParams(build)); CommonOriginRevision commonOriginRevision = getCommonOriginRevision(build); if (commonOriginRevision != null) { event diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java similarity index 70% rename from src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java rename to src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java index 2a748b76df..d68937ab57 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputExecutionParametersHelper.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java @@ -13,21 +13,22 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class OutputExecutionParametersHelper { +public class OutputEnvironmentParametersHelper { - private static final String SPLIT_SYMBOL = " "; + public static final String SPLIT_SYMBOL = " "; - public static Map getOutputExecutionParams(AbstractBuild build) { + public static Map getOutputEnvironmentParams(AbstractBuild build) { EnvVars environment = getEnvironment(build); if (environment == null) { return Collections.emptyMap(); } else { - List paramKeysList = getGlobalParamsList(); + List paramKeysList = new ArrayList<>(); + paramKeysList.addAll(getGlobalParamsList()); paramKeysList.addAll(getJobParamsList(build)); if (paramKeysList.isEmpty()) return Collections.emptyMap(); - Map outputExecutionParams = new HashMap<>(); + Map outputEnvParams = new HashMap<>(); Set sensitiveBuildVariables = build.getSensitiveBuildVariables(); String value; @@ -35,10 +36,10 @@ public static Map getOutputExecutionParams(AbstractBuild build) if (sensitiveBuildVariables.contains(key)) continue; value = environment.get(key); if (value != null) { - outputExecutionParams.put(key, value); + outputEnvParams.put(key, value); } } - return outputExecutionParams; + return outputEnvParams; } } @@ -52,15 +53,19 @@ private static EnvVars getEnvironment(AbstractBuild build) { } private static List getGlobalParamsList() { - return Stream.of(RunnerMiscSettingsGlobalConfiguration.getInstance().getOutputExecutionParameters().split(SPLIT_SYMBOL)) - .filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); + try { + return Stream.of(RunnerMiscSettingsGlobalConfiguration.getInstance().getOutputEnvironmentParameters() + .split(SPLIT_SYMBOL)).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); + } catch (NullPointerException ignored) { + return Collections.emptyList(); + } } private static List getJobParamsList(AbstractBuild build) { Job job = build.getParent(); if (job instanceof BuildableItemWithBuildWrappers) { String paramsStr = ((BuildableItemWithBuildWrappers) job).getBuildWrappersList(). - get(OctaneBuildWrapper.class).getOutputExecutionParameters(); + get(OctaneBuildWrapper.class).getOutputEnvironmentParameters(); if (paramsStr != null) { String[] params = paramsStr.split(SPLIT_SYMBOL); return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); diff --git a/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java b/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java index 4f6d7be239..db5278d9eb 100644 --- a/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java +++ b/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java @@ -18,20 +18,22 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.SPLIT_SYMBOL; + public class OctaneBuildWrapper extends BuildWrapper implements Serializable { - private String outputExecutionParameters; + private String outputEnvironmentParameters; @DataBoundConstructor - public OctaneBuildWrapper(String outputExecutionParameters) { - this.outputExecutionParameters = outputExecutionParameters; + public OctaneBuildWrapper(String outputEnvironmentParameters) { + setOutputEnvironmentParameters(outputEnvironmentParameters); } - public String getOutputExecutionParameters() { - return outputExecutionParameters; + public String getOutputEnvironmentParameters() { + return outputEnvironmentParameters; } @DataBoundSetter - public void setOutputExecutionParameters(String outputExecutionParameters) { - this.outputExecutionParameters = getValidatedOutputExecutionParameters(outputExecutionParameters); + public void setOutputEnvironmentParameters(String outputEnvironmentParameters) { + this.outputEnvironmentParameters = getValidatedOutputEnvironmentParameters(outputEnvironmentParameters); } @Override @@ -45,10 +47,10 @@ public void buildEnvVars(Map env) { }; } - private String getValidatedOutputExecutionParameters(String executionParams) { - String[] params = executionParams.split(" "); + private String getValidatedOutputEnvironmentParameters(String envParams) { + String[] params = envParams.split("\\s++"); return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)) - .collect(Collectors.joining(" ")); + .collect(Collectors.joining(SPLIT_SYMBOL)); } @@ -62,12 +64,7 @@ public boolean isApplicable(AbstractProject item) { @Override public String getDisplayName() { - return "Octane Build Environment"; - } - - @Override - public String getHelpFile() { - return "/plugin/hp-application-automation-tools-plugin/help/help-octaneBuildEnvConfig.html"; + return "Define list of Environment Variables to be sent to ALM Octane"; } } diff --git a/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java b/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java index 5ff67db768..3f3c151a90 100644 --- a/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java +++ b/src/main/java/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration.java @@ -43,6 +43,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.SPLIT_SYMBOL; + @Extension(ordinal = 1, optional = true) public class RunnerMiscSettingsGlobalConfiguration extends GlobalConfiguration implements Serializable { @@ -53,19 +55,19 @@ public class RunnerMiscSettingsGlobalConfiguration extends GlobalConfiguration i public static final List DEFAULT_UFT_DATE_PATTERNS = Arrays.asList(DEFAULT_UFT_DATE_PATTERN1, DEFAULT_UFT_DATE_PATTERN2, DEFAULT_UFT_DATE_PATTERN3); public static final String DEFAULT_BRANCHES = "master main trunk mainline"; - public static final String DEFAULT_OUTPUT_EXECUTION_PARAMETERS = "BUILD_DISPLAY_NAME BUILD_TAG BUILD_URL"; + public static final String DEFAULT_OUTPUT_ENVIRONMENT_PARAMETERS = "BUILD_DISPLAY_NAME BUILD_TAG BUILD_URL"; private String dateFormat; private String defaultBranches; - private String outputExecutionParameters; + private String outputEnvironmentParameters; private boolean agentToControllerEnabled; @DataBoundConstructor - public RunnerMiscSettingsGlobalConfiguration(String mfDateFormat, String defaultBranches, String outputExecutionParameters, boolean agentToControllerEnabled) { + public RunnerMiscSettingsGlobalConfiguration(String mfDateFormat, String defaultBranches, String outputEnvironmentParameters, boolean agentToControllerEnabled) { setDateFormat(mfDateFormat); setDefaultBranches(defaultBranches); setAgentToControllerEnabled(agentToControllerEnabled); - setOutputExecutionParameters(outputExecutionParameters); + setOutputEnvironmentParameters(outputEnvironmentParameters); } public RunnerMiscSettingsGlobalConfiguration() { @@ -105,12 +107,12 @@ public void setDefaultBranches(String defaultBranches) { save(); } - public String getOutputExecutionParameters() { - return outputExecutionParameters; + public String getOutputEnvironmentParameters() { + return outputEnvironmentParameters; } - public void setOutputExecutionParameters(String outputExecutionParameters) { - this.outputExecutionParameters = getValidatedOutputExecutionParameters(outputExecutionParameters); + public void setOutputEnvironmentParameters(String outputEnvironmentParameters) { + this.outputEnvironmentParameters = getValidatedOutputEnvironmentParameters(outputEnvironmentParameters); save(); } @@ -120,10 +122,10 @@ private String getValidatedDefaultBranches(String defaultBranches) { .collect(Collectors.joining(" ")); } - private String getValidatedOutputExecutionParameters(String executionParams) { - String[] props = executionParams.split(" "); - return Stream.of(props).filter(p -> !StringUtils.isNullOrEmpty(p)) - .collect(Collectors.joining(" ")); + private String getValidatedOutputEnvironmentParameters(String envParams) { + String[] params = envParams.split("\\s++"); + return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)) + .collect(Collectors.joining(SPLIT_SYMBOL)); } public DateTimeFormatter getDateFormatter() { diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly index 7169f56703..8d68d846c0 100644 --- a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly @@ -28,7 +28,7 @@ --> - - + + diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputEnvironmentParameters.html similarity index 86% rename from src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html rename to src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputEnvironmentParameters.html index 9a4b84d46c..e62677a2f3 100644 --- a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputExecutionParameters.html +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputEnvironmentParameters.html @@ -27,7 +27,7 @@ -->
- Define properties of a specific job, additional to the properties specified in the global settings. After the build is complete, Jenkins will pass these properties to a respective auto action. + Define list of Environment Variables of a specific job to be sent to ALM Octane, additional to the properties specified in the global settings. After the job is done, Jenkins will pass these properties to a respective Auto Action.
- Delimit multiple properties with a space. + Delimit multiple properties with a space or EOL.
\ No newline at end of file diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly index 3d6b3e5263..6a35a50383 100644 --- a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/config.jelly @@ -35,8 +35,8 @@ - - + + diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputEnvironmentParameters.html similarity index 83% rename from src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html rename to src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputEnvironmentParameters.html index 2e23321eba..a6bf258632 100644 --- a/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputExecutionParameters.html +++ b/src/main/resources/com/microfocus/application/automation/tools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputEnvironmentParameters.html @@ -27,5 +27,7 @@ -->
- General Output Execution Parameters, which are applied to all jobs. + Define global list of environment variables to be passed to ALM Octane. This setting apply to all jobs. After the job is done, Jenkins passes listed parameters to a respective Auto Action. Delimit multiple parameters with a space or EOL. +
+ To define list of environment variables for a specific job, go to the Build Environment tab of that job.
\ No newline at end of file diff --git a/src/main/webapp/help/help-octaneBuildEnvConfig.html b/src/main/webapp/help/help-octaneBuildEnvConfig.html deleted file mode 100644 index 6926445e27..0000000000 --- a/src/main/webapp/help/help-octaneBuildEnvConfig.html +++ /dev/null @@ -1,31 +0,0 @@ - - -
- ALM Octane related Environment configuration -
\ No newline at end of file From 473dcf88b0b7ff6e35a2596366e9c4eb3856ddd4 Mon Sep 17 00:00:00 2001 From: Bohdan Bokhonko Date: Thu, 26 Jan 2023 17:26:02 +0200 Subject: [PATCH 3/4] US #2048033: Extend polling to send/receive custom properties --- .../OutputEnvironmentParametersHelper.java | 22 +++++++++++-------- .../projects/AbstractProjectProcessor.java | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java index d68937ab57..e7890ed662 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java @@ -7,6 +7,7 @@ import hudson.model.AbstractBuild; import hudson.model.BuildableItemWithBuildWrappers; import hudson.model.Job; +import hudson.model.Run; import java.io.IOException; import java.util.*; @@ -17,23 +18,26 @@ public class OutputEnvironmentParametersHelper { public static final String SPLIT_SYMBOL = " "; - public static Map getOutputEnvironmentParams(AbstractBuild build) { - EnvVars environment = getEnvironment(build); + public static Map getOutputEnvironmentParams(Run run) { + EnvVars environment = getEnvironment(run); if (environment == null) { return Collections.emptyMap(); } else { List paramKeysList = new ArrayList<>(); paramKeysList.addAll(getGlobalParamsList()); - paramKeysList.addAll(getJobParamsList(build)); + paramKeysList.addAll(getJobParamsList(run)); if (paramKeysList.isEmpty()) return Collections.emptyMap(); Map outputEnvParams = new HashMap<>(); - Set sensitiveBuildVariables = build.getSensitiveBuildVariables(); + Set sensitiveBuildVariables =null; + if (run instanceof AbstractBuild) { + sensitiveBuildVariables = ((AbstractBuild) run).getSensitiveBuildVariables(); + } String value; for (String key : paramKeysList) { - if (sensitiveBuildVariables.contains(key)) continue; + if (sensitiveBuildVariables != null && sensitiveBuildVariables.contains(key)) continue; value = environment.get(key); if (value != null) { outputEnvParams.put(key, value); @@ -43,10 +47,10 @@ public static Map getOutputEnvironmentParams(AbstractBuild build } } - private static EnvVars getEnvironment(AbstractBuild build) { + private static EnvVars getEnvironment(Run run) { EnvVars environment = null; try { - environment = build.getEnvironment(null); + environment = run.getEnvironment(null); } catch (IOException | InterruptedException ignored) { } return environment; @@ -61,8 +65,8 @@ private static List getGlobalParamsList() { } } - private static List getJobParamsList(AbstractBuild build) { - Job job = build.getParent(); + private static List getJobParamsList(Run run) { + Job job = run.getParent(); if (job instanceof BuildableItemWithBuildWrappers) { String paramsStr = ((BuildableItemWithBuildWrappers) job).getBuildWrappersList(). get(OctaneBuildWrapper.class).getOutputEnvironmentParameters(); diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java b/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java index 8eb85f9170..51f4e7218a 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java @@ -52,6 +52,8 @@ import java.util.List; import java.util.Set; +import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.getOutputEnvironmentParams; + /** * Created with IntelliJ IDEA. * User: gullery @@ -209,6 +211,7 @@ public CIBuildStatusInfo getBuildStatus(String paramName, String paramValue) { } else { status.setBuildStatus(CIBuildStatus.FINISHED); status.setResult(BuildHandlerUtils.translateRunResult(aBuild)); + status.setEnvironmentOutputtedParameters(getOutputEnvironmentParams(aBuild)); } status.setAllBuildParams(ParameterProcessors.getInstances(aBuild)); status.setBuildCiId(BuildHandlerUtils.getBuildCiId(aBuild)); From a0ad83da307026cae0eac546e4ec50697c350b26 Mon Sep 17 00:00:00 2001 From: Bohdan Bokhonko Date: Tue, 31 Jan 2023 20:51:12 +0200 Subject: [PATCH 4/4] US #2048033: Refactoring --- pom.xml | 2 +- .../AbstractBuildListenerOctaneImpl.java | 4 +--- .../OutputEnvironmentParametersHelper.java | 22 +++++++++++++------ .../events/WorkflowListenerOctaneImpl.java | 3 ++- .../projects/AbstractProjectProcessor.java | 5 ++--- ...tputEnvironmentVariablesBuildWrapper.java} | 4 ++-- .../config.jelly | 0 .../help-outputEnvironmentParameters.html | 0 8 files changed, 23 insertions(+), 17 deletions(-) rename src/main/java/com/microfocus/application/automation/tools/settings/{OctaneBuildWrapper.java => OutputEnvironmentVariablesBuildWrapper.java} (91%) rename src/main/resources/com/microfocus/application/automation/tools/settings/{OctaneBuildWrapper => OutputEnvironmentVariablesBuildWrapper}/config.jelly (100%) rename src/main/resources/com/microfocus/application/automation/tools/settings/{OctaneBuildWrapper => OutputEnvironmentVariablesBuildWrapper}/help-outputEnvironmentParameters.html (100%) diff --git a/pom.xml b/pom.xml index 15f512b69f..9a6a276727 100644 --- a/pom.xml +++ b/pom.xml @@ -489,7 +489,7 @@ integrations-sdk com.hpe.adm.octane.ciplugins - 2.7.7.0 + 2.7.8.0 diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java index 0b3e119222..08afe8f73a 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/AbstractBuildListenerOctaneImpl.java @@ -55,8 +55,6 @@ import java.util.List; -import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.getOutputEnvironmentParams; - /** * Run Listener that handles basic CI events and dispatches notifications to the Octane server * User: gullery @@ -129,7 +127,7 @@ private void publishFinishEvent(AbstractBuild build) { .setResult(BuildHandlerUtils.translateRunResult(build)) .setDuration(build.getDuration()) .setTestResultExpected(hasTests) - .setEnvironmentOutputtedParameters(getOutputEnvironmentParams(build)); + .setEnvironmentOutputtedParameters(OutputEnvironmentParametersHelper.getOutputEnvironmentParams(build)); CommonOriginRevision commonOriginRevision = getCommonOriginRevision(build); if (commonOriginRevision != null) { event diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java index e7890ed662..b407621bca 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java @@ -1,6 +1,7 @@ package com.microfocus.application.automation.tools.octane.events; -import com.microfocus.application.automation.tools.settings.OctaneBuildWrapper; +import com.microfocus.application.automation.tools.octane.configuration.SDKBasedLoggerProvider; +import com.microfocus.application.automation.tools.settings.OutputEnvironmentVariablesBuildWrapper; import com.microfocus.application.automation.tools.settings.RunnerMiscSettingsGlobalConfiguration; import com.microfocus.application.automation.tools.sse.common.StringUtils; import hudson.EnvVars; @@ -8,6 +9,7 @@ import hudson.model.BuildableItemWithBuildWrappers; import hudson.model.Job; import hudson.model.Run; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.util.*; @@ -18,6 +20,8 @@ public class OutputEnvironmentParametersHelper { public static final String SPLIT_SYMBOL = " "; + private static Logger logger = SDKBasedLoggerProvider.getLogger(OutputEnvironmentParametersHelper.class); + public static Map getOutputEnvironmentParams(Run run) { EnvVars environment = getEnvironment(run); if (environment == null) { @@ -51,7 +55,8 @@ private static EnvVars getEnvironment(Run run) { EnvVars environment = null; try { environment = run.getEnvironment(null); - } catch (IOException | InterruptedException ignored) { + } catch (IOException | InterruptedException e) { + logger.error("Can not get Run(id: " + run.getId() + ") Environment: " + e.getMessage()); } return environment; } @@ -68,11 +73,14 @@ private static List getGlobalParamsList() { private static List getJobParamsList(Run run) { Job job = run.getParent(); if (job instanceof BuildableItemWithBuildWrappers) { - String paramsStr = ((BuildableItemWithBuildWrappers) job).getBuildWrappersList(). - get(OctaneBuildWrapper.class).getOutputEnvironmentParameters(); - if (paramsStr != null) { - String[] params = paramsStr.split(SPLIT_SYMBOL); - return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); + OutputEnvironmentVariablesBuildWrapper outputEnvVarsBuildWrapper = ((BuildableItemWithBuildWrappers) job) + .getBuildWrappersList().get(OutputEnvironmentVariablesBuildWrapper.class); + if (outputEnvVarsBuildWrapper != null) { + String paramsStr = outputEnvVarsBuildWrapper.getOutputEnvironmentParameters(); + if (!StringUtils.isNullOrEmpty(paramsStr)) { + String[] params = paramsStr.split(SPLIT_SYMBOL); + return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)).collect(Collectors.toList()); + } } } return Collections.emptyList(); diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/events/WorkflowListenerOctaneImpl.java b/src/main/java/com/microfocus/application/automation/tools/octane/events/WorkflowListenerOctaneImpl.java index f1afdff950..09dcc46512 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/events/WorkflowListenerOctaneImpl.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/events/WorkflowListenerOctaneImpl.java @@ -169,7 +169,8 @@ private void sendPipelineFinishedEvent(WorkflowRun parentRun) { .setDuration(parentRun.getDuration()) .setResult(BuildHandlerUtils.translateRunResult(parentRun)) .setCauses(CIEventCausesFactory.processCauses(parentRun)) - .setTestResultExpected(hasTests); + .setTestResultExpected(hasTests) + .setEnvironmentOutputtedParameters(OutputEnvironmentParametersHelper.getOutputEnvironmentParams(parentRun)); CIJenkinsServicesImpl.publishEventToRelevantClients(event); } diff --git a/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java b/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java index 51f4e7218a..aaf8ac464a 100644 --- a/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java +++ b/src/main/java/com/microfocus/application/automation/tools/octane/model/processors/projects/AbstractProjectProcessor.java @@ -35,6 +35,7 @@ import com.hp.octane.integrations.utils.SdkConstants; import com.hp.octane.integrations.utils.SdkStringUtils; import com.microfocus.application.automation.tools.octane.configuration.SDKBasedLoggerProvider; +import com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper; import com.microfocus.application.automation.tools.octane.executor.UftConstants; import com.microfocus.application.automation.tools.octane.model.processors.builders.AbstractBuilderProcessor; import com.microfocus.application.automation.tools.octane.model.processors.builders.BuildTriggerProcessor; @@ -52,8 +53,6 @@ import java.util.List; import java.util.Set; -import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.getOutputEnvironmentParams; - /** * Created with IntelliJ IDEA. * User: gullery @@ -211,7 +210,7 @@ public CIBuildStatusInfo getBuildStatus(String paramName, String paramValue) { } else { status.setBuildStatus(CIBuildStatus.FINISHED); status.setResult(BuildHandlerUtils.translateRunResult(aBuild)); - status.setEnvironmentOutputtedParameters(getOutputEnvironmentParams(aBuild)); + status.setEnvironmentOutputtedParameters(OutputEnvironmentParametersHelper.getOutputEnvironmentParams(aBuild)); } status.setAllBuildParams(ParameterProcessors.getInstances(aBuild)); status.setBuildCiId(BuildHandlerUtils.getBuildCiId(aBuild)); diff --git a/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java b/src/main/java/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper.java similarity index 91% rename from src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java rename to src/main/java/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper.java index db5278d9eb..92ab46ac11 100644 --- a/src/main/java/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper.java +++ b/src/main/java/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper.java @@ -20,11 +20,11 @@ import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.SPLIT_SYMBOL; -public class OctaneBuildWrapper extends BuildWrapper implements Serializable { +public class OutputEnvironmentVariablesBuildWrapper extends BuildWrapper implements Serializable { private String outputEnvironmentParameters; @DataBoundConstructor - public OctaneBuildWrapper(String outputEnvironmentParameters) { + public OutputEnvironmentVariablesBuildWrapper(String outputEnvironmentParameters) { setOutputEnvironmentParameters(outputEnvironmentParameters); } diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly b/src/main/resources/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper/config.jelly similarity index 100% rename from src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/config.jelly rename to src/main/resources/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper/config.jelly diff --git a/src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputEnvironmentParameters.html b/src/main/resources/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper/help-outputEnvironmentParameters.html similarity index 100% rename from src/main/resources/com/microfocus/application/automation/tools/settings/OctaneBuildWrapper/help-outputEnvironmentParameters.html rename to src/main/resources/com/microfocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper/help-outputEnvironmentParameters.html