Skip to content

Commit

Permalink
Merge pull request #6 from michael1010/master
Browse files Browse the repository at this point in the history
[JENKINS-26671] Multiple description setter build steps should append
[JENKINS-16377] help text for "description setter" seems to be incorrect
[JENKINS-17461] Expose description as an environment variable
  • Loading branch information
michael1010 committed Mar 21, 2015
2 parents 965d2e9 + c8f1b3f commit 284925c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,2 +1,6 @@
description-setter.iml
target/
work/
.project
.classpath
.settings
@@ -1,14 +1,20 @@
package hudson.plugins.descriptionsetter;

import hudson.EnvVars;
import hudson.model.BuildListener;
import hudson.model.ParameterValue;
import hudson.model.AbstractBuild;
import hudson.model.ParametersAction;
import hudson.model.StringParameterValue;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -60,7 +66,19 @@ public static boolean setDescription(AbstractBuild<?, ?> build,
result = urlify(result);

build.addAction(new DescriptionSetterAction(result));
build.setDescription(result);
if(build.getDescription() == null)
{
build.setDescription(result);
}
else
{
String oldDescr = build.getDescription();
String newDescr = oldDescr + "<br />" + result;
build.setDescription(newDescr);
}

setEnvironmentVariable(result, build);

listener.getLogger().println(LOG_PREFIX + " Description set: " + result);
} catch (IOException e) {
e.printStackTrace(listener.error(LOG_PREFIX
Expand All @@ -69,6 +87,13 @@ public static boolean setDescription(AbstractBuild<?, ?> build,

return true;
}

private static void setEnvironmentVariable(String result, AbstractBuild<?, ?> build)
{
List<ParameterValue> params = new ArrayList<ParameterValue>();
params.add(new StringParameterValue("DESCRIPTION_SETTER_DESCRIPTION", result));
build.addAction(new ParametersAction(params));
}

private static Matcher parseLog(File logFile, String regexp)
throws IOException, InterruptedException {
Expand Down
Expand Up @@ -156,6 +156,12 @@ public boolean endRun(MatrixRun run) throws InterruptedException,
&& run.getDescription() != null) {
build.setDescription(run.getDescription());
}
else if(build.getDescription() != null && run.getDescription() != null)
{
String oldDescr = build.getDescription();
String newDescr = oldDescr + "<br />" + run.getDescription();
build.setDescription(newDescr);
}
return true;
}
};
Expand Down
Expand Up @@ -4,4 +4,5 @@
<li>If a regular expression is configured, every instance of \n will be replaced with the n-th group of the regular expression match.</li>
<li>If the description is empty, the first group selected by the regular expression will be used as description.</li>
<li>If no regular expression is configured, the description is taken verbatim.</li>
</ul>
</div>
Expand Up @@ -5,4 +5,7 @@
<p>
A description can be based on the log output (by searching it using a regular expression), or it can be hardcoded.
</p>
<p>
The description is exposed as DESCRIPTION_SETTER_DESCRIPTION environment variable
</p>
</div>
Expand Up @@ -4,4 +4,5 @@
<li>If a regular expression is configured, every instance of \n will be replaced with the n-th group of the regular expression match.</li>
<li>If the description is empty, the first group selected by the regular expression will be used as description.</li>
<li>If no regular expression is configured, the description is taken verbatim.</li>
</ul>
</div>
@@ -1,3 +1,3 @@
<div>
If set, this regular expression will be used instead of the regular regular expression when the build has failed.
If set, this regular expression will be used in case no hardcoded description is configured, when the build has failed.
</div>
Expand Up @@ -5,4 +5,7 @@
<p>
A description can be based on the log output (by searching it using a regular expression), or it can be hardcoded.
</p>
<p>
The description is exposed as DESCRIPTION_SETTER_DESCRIPTION environment variable
</p>
</div>

0 comments on commit 284925c

Please sign in to comment.