The problem is that there's no existing Api object that includes Recorder in its object graph. It's bit like you've built your house all correctly but there's no road to get to it.

You can add the following to your publisher:

    public final Api getApi() {
        return new Api(this);
    }

... but I then noticed that a Recorder object isn't bound to URL, so there's no URL that takes you to this Api object.

Let me add that to the core.


On 06/27/2012 04:56 AM, David Tolley wrote:
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";


--
Kohsuke Kawaguchi | CloudBees, Inc. | http://cloudbees.com/
Try Nectar, our professional version of Jenkins


Reply via email to