Hello,
I am trying to expose some data to the API from a post-build step, and I am
not having much luck at getting the data into the API. I have added the
@Extension and @ExtensionBean annotations, and still nothing is showing up
for me. Here is what I have, any ideas as to why I can't access the exposed
info from the API?
package com.groupon.injectartifactintoapi;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.*;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import java.io.*;
@ExportedBean
public class InjectArtifactIntoAPI extends Recorder {
public final String artifactName;
@Exported
public String revision;
@DataBoundConstructor
public InjectArtifactIntoAPI(String artifactName) {
this.artifactName = artifactName;
}
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
if (build.getHasArtifacts()) {
for (Run.Artifact artifact : build.getArtifacts()) {
if (artifact.getFileName() == artifactName) {
FileInputStream fstream = new
FileInputStream(artifact.getFileName());
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
revision = br.readLine();
System.out.println(revision);
}
}
}
final PrintStream logger = listener.getLogger();
logger.println(StringUtils.defaultString(revision));
revision = "243dffefef";