Hudson/Jenkins Plugin development: how to get environment variables of other plugin
Asked Answered
D

3

9

I'm in a somewhat old Hudson configuration. We have an in house developed plugin that query a Nexus repository and set some job parameters. The plugin is in Java.

We also use the depreacated SetEnv Plugin, where we set a bunch of environment variables.

Our plugin, basically extends the ParameterDefinition class to give a bunch of options in the build job screen, then a ParameterValue class set environment variables for our jobs.

Our Parameter Definition classe:

class NexusQueryParameterDefinition extends ParameterDefinition

Is it possible to access the environment variables defined in the SetEnv plugin from our Parameter Definition class?

The problem that I'm at definition time of a a parametrized build, that is the screen between when I press the button "build now" and when I press the button "Build" to start the process. At this point I don't know how to access the job instance object and I believe the build object just will be created when the form is submitted.

These environment variables are persisted in the config.xml, so if I can read this file I can parse the values.

Decentralization answered 18/9, 2017 at 22:18 Comment(0)
D
0

It looks like it isn't possible without changing Hudson/Jenkins code.

Here is a link about it: https://groups.google.com/forum/#!topic/jenkinsci-dev/2hLy525cxsg

Decentralization answered 28/9, 2017 at 19:13 Comment(0)
P
0

I would suggest you explore using the Environment Injector plugin and groovy code to return a map object in the Set Environment for a Run option in the job configuration.

Pier answered 28/9, 2017 at 6:1 Comment(0)
D
0

It looks like it isn't possible without changing Hudson/Jenkins code.

Here is a link about it: https://groups.google.com/forum/#!topic/jenkinsci-dev/2hLy525cxsg

Decentralization answered 28/9, 2017 at 19:13 Comment(0)
T
-1

Have you tried if the environment variables are already injected to the runtime? Means to access a environment property with System.getenv("yourEnvVar");

If you want to access the configured Env-Params of the SetEnv-Plugin for a migration path, it will be trickier. But for the migation cse I would suggest to read the config.xml and to pull the configuration in your plugin itself.

Translative answered 28/9, 2017 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.