This worked like a charm! The environment variable is now available in 
other build-steps, even in a shell one. :)
Class:
/**
 * An action to publish a single environment variable.
 */
public class PublishEnvVarAction extends InvisibleAction implements 
EnvironmentContributingAction {

    /** The environment variable key. */
    private String key;

    /** The environment variable value. */
    private String value;
    
    /**
     * Constructor.
     * @param key the environment variable key
     * @param value the environment variable value
     */
    public PublishEnvVarAction(String key, String value) {
        this.key = key;
        this.value = value;
    }
    
    /* (non-Javadoc)
     * @see 
hudson.model.EnvironmentContributingAction#buildEnvVars(hudson.model.AbstractBuild,
 
hudson.EnvVars)
     */
    public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
        env.put(key, value);
    }

}

In my Builder:
build.addAction(new PublishEnvVarAction("FOO", "BAR"));

On Wednesday, February 27, 2013 3:45:25 PM UTC+1, cjo wrote:
>
> Or have your builder add an action that implements 
> EnviromentContributingAction [1] to the build, normally extending 
> from InvisibleAction [2]
> via build.getActions().add(<yourAction>);
>
> Chris
>
> [1] 
> http://javadoc.jenkins-ci.org/hudson/model/EnvironmentContributingAction.html
> [2] http://javadoc.jenkins-ci.org/hudson/model/InvisibleAction.html
>
> On Wednesday, 27 February 2013 14:34:24 UTC, slide wrote:
>>
>> Does [1] help at all?
>>
>>
>> slide
>>
>> 1 - https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin
>>
>>
>> On Wed, Feb 27, 2013 at 7:30 AM, PhilipLB <[email protected]> wrote:
>>
>>> This was too optimistic:
>>> build.getEnvironment(listener).put("FOO", "BAR");
>>>
>>> In a later buildstep, the "FOO" env var is still null.
>>>
>>>
>>> On Wednesday, February 27, 2013 3:00:47 PM UTC+1, PhilipLB wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'd like to set an environment variable from within the execution of my 
>>>> Builder (in my plugin). How do I do this? SCM plugins have their 
>>>> buildEnvVars-method (or similar), but the Builder doesn't...
>>>> Any help would be greatly appreciated!
>>>>
>>>> Best regards,
>>>> Philip
>>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>>
>> -- 
>> Website: http://earl-of-code.com 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to