Quantcast

Cannot add environment variables in plugin?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Cannot add environment variables in plugin?

ThomasBrouwer
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

vlatombe
Hi Thomas,

I just copy pasted your code into a plugin project and on my side this seems to work fine.

How are you running/debugging your plugin?

Vincent


2012/8/21 ThomasBrouwer <[hidden email]>
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

ThomasBrouwer
In reply to this post by ThomasBrouwer
Hi Vincent,

Thanks for replying :)
My debugging setup does not work, so I simply do install on the project, and then load the output .hpi file into my Jenkins. 
So strange that it works for you. Do you have any jelly files or such made for this class? Perhaps one of my plugins is conflicting with it? 

My plugins are:
1.1
Integrates Jenkins with CVS version control system.
1.6
This plugin integrates GIT with Jenkins.
1.1.21
Because green is better than blue! For color blind support configure user property.
1.12
This plugin adds locking and latch functionality to Hudson.
0.6
1.0
This plugin manage exclusion between jobs.
0.7
2.15
This plugin provides SCons support in Jenkins.
0.4
0.21
This plugin publishes TAP test results.
1.3
1.1
1.472
1.0
1.2.1
1.0
This plugin is a sample to explain how to write a Jenkins plugin.
1.0-SNAPSHOT (private-08/14/2012 16:30-tbrouwer)
This plug-in provides utilities for the static code analysis plug-ins.

If you like this open source plug-in please consider supporting my work by buying my Android game Inca Trails.

1.43
1.34
This plugin allows for throttling the number of concurrent builds of a project running per node or globally.
testing_1639
This plug-in adds reusable macro expansion capability for other plug-ins to use.
1.5.1
1.8
This plug-in collects the compiler warnings of the project modules and visualizes the results.

If you like this open source plug-in please consider supporting my work by buying my Android game Inca Trails.

4.13
Workspace Cleanup Plugin

Just to confirm: this should just hook into Jenkins without any triggers from our side? Just having this code and loading in this plugin should already add the environmental variable?

Thomas

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

ThomasBrouwer
In reply to this post by ThomasBrouwer
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

vlatombe
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 <[hidden email]>
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

ThomasBrouwer
In reply to this post by ThomasBrouwer
Hi Vincent,

Thanks for the reply!
Unfortunately hpi:run doesn't work well for me, just gives me weird Java errors. Probably something with the network messed up, too much effort to fix it anyways.
The weird thing is that buildEnvironmentFor() is never even executed, so changing it to a log would not work... 
I'll give the clean command a try tomorrow, see if it works. If not then I'll have to give up on this...
Do you perhaps know when exactly this function is supposed to be called? Is it called when a job is built, or when job configs is saved, or when the global configs are saved? That might help me track it down :)

Thanks!
Thomas

Op dinsdag 21 augustus 2012 15:57:12 UTC+1 schreef ThomasBrouwer het volgende:
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

vlatombe
Hi,

it should be called at least when the job is built.

Vincent


2012/8/21 ThomasBrouwer <[hidden email]>
Hi Vincent,

Thanks for the reply!
Unfortunately hpi:run doesn't work well for me, just gives me weird Java errors. Probably something with the network messed up, too much effort to fix it anyways.
The weird thing is that buildEnvironmentFor() is never even executed, so changing it to a log would not work... 
I'll give the clean command a try tomorrow, see if it works. If not then I'll have to give up on this...
Do you perhaps know when exactly this function is supposed to be called? Is it called when a job is built, or when job configs is saved, or when the global configs are saved? That might help me track it down :)

Thanks!
Thomas

Op dinsdag 21 augustus 2012 15:57:12 UTC+1 schreef ThomasBrouwer het volgende:
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cannot add environment variables in plugin?

ThomasBrouwer
In reply to this post by ThomasBrouwer
The mvn clean command worked :D that you so much for the help!

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
Loading...