From cb87235248adec70ba432420f4ed98dd7d888a52 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 26 Apr 2017 13:18:17 +0200 Subject: [PATCH] get Environment from the parent MatrixBuild if we are in a MatrixRun --- .../environment/GitLabEnvironmentContributor.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dabsquared/gitlabjenkins/environment/GitLabEnvironmentContributor.java b/src/main/java/com/dabsquared/gitlabjenkins/environment/GitLabEnvironmentContributor.java index 86e02e7..5b65c9c 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/environment/GitLabEnvironmentContributor.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/environment/GitLabEnvironmentContributor.java @@ -3,6 +3,8 @@ package com.dabsquared.gitlabjenkins.environment; import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause; import hudson.EnvVars; import hudson.Extension; +import hudson.matrix.MatrixRun; +import hudson.matrix.MatrixBuild; import hudson.model.EnvironmentContributor; import hudson.model.Run; import hudson.model.TaskListener; @@ -17,7 +19,15 @@ import java.io.IOException; public class GitLabEnvironmentContributor extends EnvironmentContributor { @Override public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { - GitLabWebHookCause cause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class); + GitLabWebHookCause cause = null; + if (r instanceof MatrixRun) { + MatrixBuild parent = ((MatrixRun)r).getParentBuild(); + if (parent != null) { + cause = (GitLabWebHookCause) parent.getCause(GitLabWebHookCause.class); + } + } else { + cause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class); + } if (cause != null) { envs.overrideAll(cause.getData().getBuildVariables()); }