Defining *project level* environemnt variables

40 views
Skip to first unread message

Sébastien Hinderer

unread,
Oct 21, 2017, 10:24:48 AM10/21/17
to jenkins...@googlegroups.com
Dear all,

I would like to be able to define an environment variable for Jenkins
but not at the job level, rather at the project level, so that it can be
shared between several different jobs.
Moreover I would like to be able to do this from the web interface,
because I do not have ssh access to the Jenkins server.

Is there a way to achieve this? I looked at the env injector plugin but
I believe it won't work for my use case.

Many thanks in advance for any hint,

Sébastien.

Stephen Connolly

unread,
Oct 21, 2017, 10:46:40 AM10/21/17
to jenkins...@googlegroups.com
A folder property can contribute env vars.

My employer has this functionality I think in our folders-plus plugin... it’s not too hard to write, but sales blocked us open-sourcing it at the time (they’d probably be fine now, but I don’t have the energy to chase it)

Somebody may have already implemented it... if not, you could give it a shot and file a PR against the folder plugin to help us force the decision ;-)

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/20171021132148.cabsf3ez3xksaffq%40pl-59055.rocqadm.inria.fr.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

Dan Tran

unread,
Oct 21, 2017, 1:30:07 PM10/21/17
to Jenkins Users
Here is the Jira https://issues.jenkins-ci.org/browse/JENKINS-42906 filed some time ago

Sébastien Hinderer

unread,
Oct 25, 2017, 2:39:09 PM10/25/17
to jenkins...@googlegroups.com
Thanks a lot for your response, Stephen.
Not sure I'm brave enough to try to write something myself.
Just too bad it does not already exist but I guess we'll just do without
since it'd be a nice addition but not really mandatory.

Best wishes,

Sébastien.

Brian Ray

unread,
Dec 5, 2017, 4:57:46 PM12/5/17
to Jenkins Users
We use the Config File Provider plugin and the Pipeline Utilities Steps plugin in conjunction with folders to get around the JENKINS-42906 gap, in a Scripted Pipeline context.

This is actually nicer IMHO than the hidden env variables functionality, because you can use various flavors of configuration files, use an editor that understands your flavor(s) of choice, and then paste back into the UI.

In our case we're just using simple Java properties files something like the following.

  def props
  node
() {
    configFileProvider
( [ configFile( fileId: 'your-folder-cfg-file-id', variable: 'WHATEVER', replaceTokens: true ) ] ) {
      props
= readProperties( file: WHATEVER )
   
}
 
}
 
//now go do stuff with the props Map, even massaging for consumption by withEnv() ...

The ony downside is, I suppose, is the hacky nature of having the properties written down to the agent's workspace just to read them right back again and discard the file.

Brian

Brian Ray

unread,
Dec 5, 2017, 4:59:09 PM12/5/17
to Jenkins Users
Forgot to write: We mitigate the hack by wrapping it up as a global library custom step.
Reply all
Reply to author
Forward
0 new messages