Skip to content

Commit

Permalink
[JENKINS-36237] - Improve diagnostics of issues in EnvInjectBuildWrap…
Browse files Browse the repository at this point in the history
…per (#105)

Now EnvInjectBuildWrapper#setUp() provides more info in the build log and also forwards stacktrace to the system log.
In addition, we rethrow Errors since we cannot recover from them
  • Loading branch information
oleg-nenashev committed Sep 26, 2016
1 parent e58e0c4 commit a898912
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -18,6 +18,8 @@
import hudson.scm.SCM;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import net.sf.json.JSONObject;

Expand All @@ -35,7 +37,9 @@ public class EnvInjectBuildWrapper extends BuildWrapper implements Serializable

@Nonnull
private EnvInjectJobPropertyInfo info;


private static final Logger LOGGER = Logger.getLogger(EnvInjectBuildWrapper.class.getName());

@DataBoundConstructor
public EnvInjectBuildWrapper(@Nonnull EnvInjectJobPropertyInfo info) {
this.info = info;
Expand Down Expand Up @@ -120,8 +124,13 @@ public void buildEnvVars(Map<String, String> env) {
}
};
} catch (Throwable throwable) {
logger.error("Problems occurs on injecting env vars as a build wrap: " + throwable.getMessage());
logger.error("Problems occurs on injecting env vars defined in the build wrapper: " + throwable + ". See system log for more info");
LOGGER.log(Level.WARNING, String.format("Problems occurs on injecting env vars defined in the build wrapper for build {0}", build), throwable);
build.setResult(Result.FAILURE);
if (throwable instanceof Error) {
// Errors must be always propagated since we cannot recover from them
throw (Error)throwable;
}
return null;
}
}
Expand Down

0 comments on commit a898912

Please sign in to comment.