Hi,
thanks for the suggestions.
Sidenote: This solution, using environment variables used to work and afaik, we
didn't make any pipeline changes, related to this. Unfortunately I can't narrow
down, since when exactly it broke.
I can confirm, that allowing undefined parameters (JENKINS-56875) does not help.
I realized, that the environment, returned by Run.getEnvironment() does not
even contain my custom environment variables, when I call it on
currentBuild.rawBuild.
So this issue is not even related to a upstream/downstream relation between two
pipelines.
The getEnvironment() method simply seems to behave differently since…???
Here is my simplified example.
pipeline {
agent {
label 'Linux-Test'
}
environment {
name = 'foo'
}
stages {
stage('Set environment') {
environment {
name = 'bar'
}
steps {
echo
"${currentBuild.rawBuild.getEnvironment(TaskListener.NULL)}"
}
}
}
}
environment (from console log):
[BUILD_DISPLAY_NAME:#5, BUILD_ID:5, BUILD_NUMBER:5,
BUILD_TAG:jenkins-upstream-pipeline-5, BUILD_TIMESTAMP:2020-02-26_13-20-47,
BUILD_URL:https://jenkins-test8080/job/upstream-pipeline/5/, CLASSPATH:,
GIT_HOME:C:\ tools\git, HUDSON_HOME:c:\jenkins\jenkins-test,
HUDSON_SERVER_COOKIE:662af83ef93bf80d, HUDSON_URL:https://jenkins-test:8080/,
JDK_18_LATEST_X64:C:\SPU\ext64\jdk1.8.0_112,
jenkins.slaves.DefaultJnlpSlaveReceiver.disableStrictVerification:true,
JENKINS_HOME:c:\jenkins\jenkins-test, JENKINS_SERVER_COOKIE:662af83ef93bf80d,
JENKINS_URL:https://jenkins-test.dst.tk-inline.net:8080/,
JOB_BASE_NAME:upstream-pipeline,
JOB_DISPLAY_URL:https://jenkins-test.dst.tk-inline.net:8080/job/upstream-pipeline/display/redirect,
JOB_NAME:upstream-pipeline,
JOB_URL:https://jenkins-test:8080/job/upstream-pipeline/,
RUN_CHANGES_DISPLAY_URL:https://jenkins-test:8080/job/upstream-pipeline/5/display/redirect?page=changes,
RUN_DISPLAY_URL:https://jenkins-test:8080/job/upstream-pipeline/5/display/redirect]
Still hoping, that there is a way to get the complete environment…
Best regards
Stefan
Von: [email protected] [mailto:[email protected]]
Im Auftrag von Mark Waite
Gesendet: Dienstag, 25. Februar 2020 19:07
An: Jenkins Users <[email protected]>
Betreff: Re: Use environment variable from upstream build
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]<mailto:[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]>
[mailto:[email protected]<mailto:[email protected]>]
Im Auftrag von [email protected]<mailto:[email protected]>
Gesendet: Montag, 24. Februar 2020 17:33
An: [email protected]<mailto:[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]<mailto:[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]<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtGixiNpgOKp4XDaaA2raaKFj82GdA1OouKyFLmGDtyyZw%40mail.gmail.com<https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtGixiNpgOKp4XDaaA2raaKFj82GdA1OouKyFLmGDtyyZw%40mail.gmail.com?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/f75b26c07a43435990a776bef04366bb%40tk.de.