Skip to content

Commit

Permalink
US #2048033: Extend polling to send/receive custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bbokhonko-mf committed Jan 26, 2023
1 parent 2a62478 commit 473dcf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -17,23 +18,26 @@ public class OutputEnvironmentParametersHelper {

public static final String SPLIT_SYMBOL = " ";

public static Map<String, String> getOutputEnvironmentParams(AbstractBuild build) {
EnvVars environment = getEnvironment(build);
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(build));
paramKeysList.addAll(getJobParamsList(run));

if (paramKeysList.isEmpty()) return Collections.emptyMap();

Map<String, String> outputEnvParams = new HashMap<>();
Set<String> sensitiveBuildVariables = build.getSensitiveBuildVariables();
Set<String> 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);
Expand All @@ -43,10 +47,10 @@ public static Map<String, String> 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;
Expand All @@ -61,8 +65,8 @@ private static List<String> getGlobalParamsList() {
}
}

private static List<String> getJobParamsList(AbstractBuild build) {
Job<?, ?> job = build.getParent();
private static List<String> getJobParamsList(Run run) {
Job<?, ?> job = run.getParent();
if (job instanceof BuildableItemWithBuildWrappers) {
String paramsStr = ((BuildableItemWithBuildWrappers) job).getBuildWrappersList().
get(OctaneBuildWrapper.class).getOutputEnvironmentParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 473dcf8

Please sign in to comment.