forked from hpsa/hpe-application-automation-tools-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hpsa#278 from bbokhonko-mf/octane-dev-latest
US: #2029018 Send custom properties to ALM Octane on Job completion
- Loading branch information
Showing
11 changed files
with
288 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...rofocus/application/automation/tools/octane/events/OutputEnvironmentParametersHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.microfocus.application.automation.tools.octane.events; | ||
|
||
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; | ||
import hudson.model.AbstractBuild; | ||
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.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class OutputEnvironmentParametersHelper { | ||
|
||
public static final String SPLIT_SYMBOL = " "; | ||
|
||
private static Logger logger = SDKBasedLoggerProvider.getLogger(OutputEnvironmentParametersHelper.class); | ||
|
||
public static Map<String, String> getOutputEnvironmentParams(Run run) { | ||
EnvVars environment = getEnvironment(run); | ||
if (environment == null) { | ||
return Collections.emptyMap(); | ||
} else { | ||
List<String> paramKeysList = new ArrayList<>(); | ||
paramKeysList.addAll(getGlobalParamsList()); | ||
paramKeysList.addAll(getJobParamsList(run)); | ||
|
||
if (paramKeysList.isEmpty()) return Collections.emptyMap(); | ||
|
||
Map<String, String> outputEnvParams = new HashMap<>(); | ||
Set<String> sensitiveBuildVariables =null; | ||
if (run instanceof AbstractBuild) { | ||
sensitiveBuildVariables = ((AbstractBuild) run).getSensitiveBuildVariables(); | ||
} | ||
|
||
String value; | ||
for (String key : paramKeysList) { | ||
if (sensitiveBuildVariables != null && sensitiveBuildVariables.contains(key)) continue; | ||
value = environment.get(key); | ||
if (value != null) { | ||
outputEnvParams.put(key, value); | ||
} | ||
} | ||
return outputEnvParams; | ||
} | ||
} | ||
|
||
private static EnvVars getEnvironment(Run run) { | ||
EnvVars environment = null; | ||
try { | ||
environment = run.getEnvironment(null); | ||
} catch (IOException | InterruptedException e) { | ||
logger.error("Can not get Run(id: " + run.getId() + ") Environment: " + e.getMessage()); | ||
} | ||
return environment; | ||
} | ||
|
||
private static List<String> getGlobalParamsList() { | ||
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<String> getJobParamsList(Run run) { | ||
Job<?, ?> job = run.getParent(); | ||
if (job instanceof BuildableItemWithBuildWrappers) { | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rofocus/application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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; | ||
|
||
import static com.microfocus.application.automation.tools.octane.events.OutputEnvironmentParametersHelper.SPLIT_SYMBOL; | ||
|
||
public class OutputEnvironmentVariablesBuildWrapper extends BuildWrapper implements Serializable { | ||
|
||
private String outputEnvironmentParameters; | ||
@DataBoundConstructor | ||
public OutputEnvironmentVariablesBuildWrapper(String outputEnvironmentParameters) { | ||
setOutputEnvironmentParameters(outputEnvironmentParameters); | ||
} | ||
|
||
public String getOutputEnvironmentParameters() { | ||
return outputEnvironmentParameters; | ||
} | ||
@DataBoundSetter | ||
public void setOutputEnvironmentParameters(String outputEnvironmentParameters) { | ||
this.outputEnvironmentParameters = getValidatedOutputEnvironmentParameters(outputEnvironmentParameters); | ||
} | ||
|
||
@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<String, String> env) { | ||
env.putAll(envVars); | ||
} | ||
}; | ||
} | ||
|
||
private String getValidatedOutputEnvironmentParameters(String envParams) { | ||
String[] params = envParams.split("\\s++"); | ||
return Stream.of(params).filter(p -> !StringUtils.isNullOrEmpty(p)) | ||
.collect(Collectors.joining(SPLIT_SYMBOL)); | ||
} | ||
|
||
|
||
@Extension | ||
public static final class DescriptorImpl extends BuildWrapperDescriptor { | ||
|
||
@Override | ||
public boolean isApplicable(AbstractProject<?, ?> item) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Define list of Environment Variables to be sent to ALM Octane"; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...application/automation/tools/settings/OutputEnvironmentVariablesBuildWrapper/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?jelly escape-by-default='true'?> | ||
<!-- | ||
~ Certain versions of software and/or documents ("Material") accessible here may contain branding from | ||
~ Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, | ||
~ the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP | ||
~ and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE | ||
~ marks are the property of their respective owners. | ||
~ __________________________________________________________________ | ||
~ MIT License | ||
~ | ||
~ (c) Copyright 2012-2021 Micro Focus or one of its affiliates. | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
~ documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
~ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
~ and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in all copies or | ||
~ substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
~ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
~ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
~ SOFTWARE. | ||
~ | ||
~ ___________________________________________________________________ | ||
--> | ||
|
||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry title="List of output Environment Variables" field="outputEnvironmentParameters"> | ||
<f:textarea name="mf.outputEnvironmentParameters" value="${instance.outputEnvironmentParameters}"/> | ||
</f:entry> | ||
</j:jelly> |
33 changes: 33 additions & 0 deletions
33
...ols/settings/OutputEnvironmentVariablesBuildWrapper/help-outputEnvironmentParameters.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
~ Certain versions of software and/or documents ("Material") accessible here may contain branding from | ||
~ Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, | ||
~ the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP | ||
~ and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE | ||
~ marks are the property of their respective owners. | ||
~ __________________________________________________________________ | ||
~ MIT License | ||
~ | ||
~ (c) Copyright 2012-2021 Micro Focus or one of its affiliates. | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
~ documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
~ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
~ and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in all copies or | ||
~ substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
~ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
~ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
~ SOFTWARE. | ||
~ | ||
~ ___________________________________________________________________ | ||
--> | ||
|
||
<div> | ||
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. | ||
<br/> | ||
Delimit multiple properties with a space or EOL. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ools/settings/RunnerMiscSettingsGlobalConfiguration/help-outputEnvironmentParameters.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
~ Certain versions of software and/or documents ("Material") accessible here may contain branding from | ||
~ Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, | ||
~ the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP | ||
~ and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE | ||
~ marks are the property of their respective owners. | ||
~ __________________________________________________________________ | ||
~ MIT License | ||
~ | ||
~ (c) Copyright 2012-2021 Micro Focus or one of its affiliates. | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
~ documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
~ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
~ and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in all copies or | ||
~ substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
~ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
~ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
~ SOFTWARE. | ||
~ | ||
~ ___________________________________________________________________ | ||
--> | ||
|
||
<div> | ||
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. | ||
<br/> | ||
To define list of environment variables for a specific job, go to the Build Environment tab of that job. | ||
</div> |