def call(int blah) {
pipeline {
agent any
environment {
MyVar = credentials('djsjflsjfljsf')
}
stages {
stage('Stage ONE') {
steps {
echo test.methodA()
....
// vars/test.groovy
class test implements Serializable {
static methodA (){
def env = System.getenv()
return env.dump()
//return ['powershell', 'ls env:'].execute().text
}
--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/87b6e2b0-ed9a-4ede-b22c-3b06761345e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
If you’re writing a groovy class that’s run from a library in the pipeline script then you’re not going to be able to use System.getEnv().
There’s a few approaches you can take that do work:
I noticed also you’ve got a direct execution of a process commented out, don’t do that either. The same way System.getEnv() doesn’t work, doing that will not behave as expected either (Assuming the sandbox will let you)
Regards,
Daniel.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6e7e1b97-7b9c-404f-9597-8577eb739b96%40googlegroups.com.
If you’re dealing with a stubborn library that’s forcing you to use environment variables to pass in parameters you’re in for more pain than it’s worth trying to run it within the pipeline script environment.
Use it by running a groovy script externally, e.g.
sh “groovy MyScript.groovy”
and then you’ve got all the environment variables setup and you’re in a standard groovy environment without the pipeline restrictions and idiosyncrasies.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f9a07627-f0ce-4007-a4f5-54918f5d712c%40googlegroups.com.