I wonder if you need to use https://issues.jenkins-ci.org/browse/JENKINS-56875 and its "allow undefined parameters" setting to grant permission for the environment variables from the preceding job to be visible in the successor job?
Alternatively, have you considered passing the values as parameters instead of using environment variables? On Tue, Feb 25, 2020 at 8:24 AM <[email protected]> wrote: > 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]. > 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 > <https://groups.google.com/d/msgid/jenkinsci-users/c77af83b4b0440f89c0e03fb7831de50%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/CAO49JtGixiNpgOKp4XDaaA2raaKFj82GdA1OouKyFLmGDtyyZw%40mail.gmail.com.
