Hi Thomas,
I replaced
ThrottleQueueTaskDispatcher.writeMessage("Running buildEnvironmentFor()!");
with a simple listener.getLogger().println("Adding labels to environment");
then I just created a job with a single build step calling SET (I'm on
windows) and I could see the LABELS environment variable properly defined.
To run/debug jenkins plugins, I always use *mvn(debug) clean hpi:run* .
Clean is important because otherwise it may reuse classes compiled by your
IDE and miss the markers generated by the annotation processor (which are
necessary to make your extensions picked up)
Let me know if it helps.
Vincent
2012/8/21 ThomasBrouwer <[email protected]>
> Also, how did you check whether the value came through? Just created a
> test job and did echo $LABELS or something like that?
>
>
> On Tuesday, August 21, 2012 3:57:12 PM UTC+1, ThomasBrouwer wrote:
>
>> Hi there!
>>
>> I just cannot seem to be able to add environmental variables in my
>> plugin. I made a separate class extending EnvironmentContributor:
>>
>> package hudson.plugins.**throttleconcurrents;
>>
>> import hudson.EnvVars;
>> import hudson.Extension;
>> import hudson.model.**EnvironmentContributor;
>> import hudson.model.TaskListener;
>> import hudson.model.Run;
>>
>> import java.io.IOException;
>>
>> @Extension
>> public class ThrottleAddEnvVar extends EnvironmentContributor {
>> // This class is for adding the environmental variable containing the
>> assigned labels
>> @Override
>> public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener
>> listener) throws IOException, InterruptedException {
>> ThrottleQueueTaskDispatcher.**writeMessage("Running
>> buildEnvironmentFor()!");
>> //Put together category-labels string
>> String labelEnvVar = "category1|label1<>category2|**label2"; // String
>> storing the LABELS environmental variable. Form is:
>> category1|label1<>category2|**label2<>...
>> envs.put("LABELS", labelEnvVar);
>> }
>> }
>>
>> but this does not do anything at all. In fact, the **
>> ThrottleQueueTaskDispatcher.**writeMessage() call is never made so
>> buildEnvironmentFor() is simply never executed. When is this function
>> supposed to be called?
>> I've been noticing more often that having a class have @Extension does
>> not mean it is picked up. What else, besides what is above, would be
>> necessary? This generalizes to other extension points such as Builders and
>> such.
>>
>> Help will be greatly appreciated!
>> Thomas
>>
>