samrocketman / jervis

Self service Jenkins job generation using Jenkins Job DSL plugin groovy scripts. Reads .jervis.yml and generates a job in Jenkins.
http://sam.gleske.net/jervis-api/
Apache License 2.0
267 stars 45 forks source link

Pass global environment variables from .jervis.yml file to pipeline_jenkinsfile #126

Open tairov opened 6 years ago

tairov commented 6 years ago

I need to pass some variable from .jervis.yml to Jenkinsfile, but can't figure out how to do that. I was trying to set variable in env section:

env:
  - MY_VAR=xyz

But can't access that variable in Jenkinsfile

def MY_VAR = env.MY_VAR ?: 'default'
sh "echo $MY_VAR"

Each time it shows default

samrocketman commented 6 years ago

At this time, it's not designed that way. I have that planned for secrets (ref https://github.com/samrocketman/jervis/issues/103) but haven't really thought about environment variables.

One of the challenges being that env is supported in matrix builds. I suppose I could allow:

env:
  global:
    - MY_VAR=xyz

From the environment matrix to pass variables. More research would be required to support something like this.

samrocketman commented 1 year ago

I’ve been using this in production for several years and I plan to implement support for it through https://github.com/samrocketman/jervis/issues/144. This would be launching a shell and getting the same toolchain environment in a Jenkinsfile.

tairov commented 1 year ago

Hi @samrocketman , by any chance is this feature implemented ? :) do you need help with this?

samrocketman commented 1 year ago

@tairov you're welcome to try if you want. My current focus is multiplatform support with the 2.1 release.

samrocketman commented 1 year ago

I will plan to do this for 2.2 release