Expose a new global environment variable

31 views
Skip to first unread message

Miguelangel Fernandez

unread,
Oct 11, 2017, 8:25:39 AM10/11/17
to jenkin...@googlegroups.com
Hi,

I'm working on a Jenkins plugin and I have a need to make a new environment variable available to all jobs in Jenkins.
Sort of like a Jenkins global environment variable, or maybe exactly like that. I'm not sure. I just need it to be available to any script.

I already capture the value for this environment variable in one of the entries of my plugin's config.jelly file so it would feel like double work for the admin to also have to set it under "Manage Jenkins>Configure System>Global properties"

Then, as a second step, and thinking of maybe exposing others in the future, how should I go about name-spacing these? Sort of the way there are the env, params, docker, currentBuild environment variables. What should I extend in order to have my own name-spaced env vars? e.g.: foo.MY_VAR_1, foo.MY_VAR_2

Can anyone point me in the right direction?

Thank you,

                                              Miguelángel Fernández M.

Life is what happens to you while you're busy making other plans.

                                                                                    --John Lennon.

Jesse Glick

unread,
Oct 11, 2017, 3:07:03 PM10/11/17
to Jenkins Dev
On Wed, Oct 11, 2017 at 8:25 AM, Miguelangel Fernandez
<miguela...@gmail.com> wrote:
> I'm working on a Jenkins plugin and I have a need to make a new environment
> variable available to all jobs in Jenkins. Sort of like a Jenkins global
> environment variable, or maybe exactly like that. I'm not sure. I just need
> it to be available to any script.

Actual environment variable?

http://javadoc.jenkins.io/hudson/model/EnvironmentContributor.html

> how should I go about name-spacing these? Sort of the way there are the env,
> params, docker, currentBuild environment variables.

These are not environment variables. They are global variables
accessible to Groovy-based Pipeline scripts. Unrelated extension
point.

http://javadoc.jenkins.io/workflow-cps/org/jenkinsci/plugins/workflow/cps/GlobalVariable.html

(Which I do not really recommend you implement. Consider a different design.)
Reply all
Reply to author
Forward
0 new messages