Hi,

as a simple test case, I created these two pipelines.

First, the "upstream pipeline":
pipeline {
    agent {
        label 'Linux-Test'
    }

    environment {
        name = 'foo'
    }

    stages {
        stage('Set environment') {
            environment {
                name = 'bar'
            }
            steps {
                echo "name=${name}"
            }
        }
    }
}

Second, the "downstream pipeline":
pipeline {
    agent {
        label 'Linux-Test'
    }

    triggers {
        upstream(
            upstreamProjects: "upstream-pipeline",
            threshold: hudson.model.Result.SUCCESS
        )
    }

    stages {
        stage('print upstream environment') {
            steps {
                script {
                    echo 
currentBuild.rawBuild.getCause(Cause$UpstreamCause).getUpstreamRun().getEnvironment(TaskListener.NULL).toMapString()
                }
            }
        }
    }
}

Anyone?

Best regards
Stefan


Von: [email protected] [mailto:[email protected]] 
Im Auftrag von [email protected]
Gesendet: Montag, 24. Februar 2020 17:33
An: [email protected]
Betreff: [SPAM-Verdacht] Use environment variable from upstream build

Hi everyone,

I used to set an environment variable via
  env.x = "…"
in my Jenkinsfile.
Another pipeline has an upstream trigger configured and runs right after the 
first pipeline build finishes. It reads the environment from the upstream build.
It used to work, that the downstream build could make decisions, based on the 
value of x of the upstream build.

Now,
  
currentBuild.rawBuild.getCause(Cause$UpstreamCause).getUpstreamRun().getEnvironment(TaskListener.NULL)
returns all well known environment variables, like BUILD_NUMBER, JENKINS_HOME, 
etc. but NOT x anymore.

I tried different things…
·         set x in "environment { }"
·         initialize x with a default value in the top level "environment { }" 
bevor setting it in later stages
·         use env.x = …
·         use sh "export x=…"

Nothing worked to get access to x from the downstream build.

Does anyone have a hint, how to get this working again?

Thanks and best regards
Stefan

--
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 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c7050334228f44a382f82cfd69c6f965%40tk.de<https://groups.google.com/d/msgid/jenkinsci-users/c7050334228f44a382f82cfd69c6f965%40tk.de?utm_medium=email&utm_source=footer>.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c77af83b4b0440f89c0e03fb7831de50%40tk.de.

Reply via email to