Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to assert environment variables exist or get access to the "env" property for assertions? #527

Open
red8888 opened this issue May 16, 2022 · 1 comment

Comments

@red8888
Copy link

red8888 commented May 16, 2022

Describe your use-case which is not covered by existing documentation.

I do this in my pipeline:

  environmentVariablesMap.each { key ,value ->
    env[key] = value
  }

  pipeline {
  ....

I populate the env property with my own env vars before the pipeline{} directive. Does the helper provide a method of enumerating env? Or is there a way to access it?

Thanks!

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

@nre-ableton
Copy link
Contributor

Sure, you just need to access env with a binding. In other words:

Map env = binding.getVariable('env')
env.each { key, value ->
  // whatever...
}

Note that env will be empty upon initialization, see: https://github.com/jenkinsci/JenkinsPipelineUnit/blob/master/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy#L342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants