# Variable scoping recently broke or changed?

**URL:** <https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817>\
**Category:** Using Jenkins\
**Created:** [January 16, 2025, 4:03pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817 "2025-01-16T16:03:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 16, 2025, 4:03pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/1 "2025-01-16T16:03:06Z")

</div>

Hi All,

I’m hoping someone can shed some light on an issue we’re having with our Jenkins jobs.. Since ~Nov 24 it seems our jobs \*not pipeline jobs) which declare and assign a variable in one section are now unable to reference the valie of this variable in another section - the retuned valie is now empty, it’s as if the scoping has changed to the local-to-the-section whereas before it was global-to-the-script.

As such, all of our builds and deployments are now failing. I’m at a loss to explain why this has changed or how to fix it. Our server is patched ny IT once a month, maybe it was caused by an update?

For e.g.

Execute Shell/Command:  
`rpmbuild --define "_topdir ${WORKSPACE}/rpmbuild" --define="release ${BUILD_NUMBER}" -ba rpmbuild/SPECS/vcre`

* * *

$rpmbuild used to be accessable to all sections in the job, but now it evaluates to “”

## → Jenkins setup: Jenkins: 2.401.1 OS: Linux - 4.18.0-553.30.1.el8\_10.x86\_64 Java: 11.0.25 - Red Hat, Inc. (OpenJDK 64-Bit Server VM)

active-directory:2.30  
ant:481.v7b\_09e538fcca  
antisamy-markup-formatter:155.v795fb\_8702324  
apache-httpcomponents-client-4-api:4.5.13-138.v4e7d9a\_7b\_a\_e61  
authentication-tokens:1.4  
blueocean-commons:1.27.1  
blueocean-core-js:1.27.1  
blueocean-jwt:1.27.1  
blueocean-pipeline-scm-api:1.27.1  
blueocean-rest:1.27.1  
blueocean-web:1.27.1  
bouncycastle-api:2.27  
branch-api:2.1071.v1a\_188a\_562481  
build-monitor-plugin:1.13+build.202205140447  
build-timeout:1.28  
build-user-vars-plugin:1.9  
caffeine-api:3.1.8-133.v17b\_1ff2e0599  
cloud-stats:267.v577e3742c282  
cloudbees-folder:6.800.v71307ca\_b\_986b  
command-launcher:90.v669d7ccb\_7c31  
commons-lang3-api:3.17.0-84.vb\_b\_938040b\_078  
credentials:1214.v1de940103927  
credentials-binding:523.vd859a\_4b\_122e6  
deployit-plugin:23.1.0  
disk-usage:0.28  
display-url-api:2.204.vf6fddd8a\_8b\_e9  
docker-commons:1.21  
docker-java-api:3.2.13-68.va\_875df25a\_b\_45  
docker-plugin:1.3.0  
docker-workflow:563.vd5d2e5c4007f  
durable-task:504.vb10d1ae5ba2f  
envinject-api:1.199.v3ce31253ed13  
git:5.0.0  
git-client:4.1.0  
github:1.37.0  
github-api:1.303-400.v35c2d8258028  
github-branch-source:1701.v00cc8184df93  
gradle:2.3  
groovy:453.vcdb\_a\_c5c99890  
icon-shim:3.0.0  
instance-identity:142.v04572ca\_5b\_265  
ionicons-api:56.v1b\_1c8c49374e  
jackson2-api:2.15.2-350.v0c2f3f8fc595  
jakarta-activation-api:2.0.1-3  
jakarta-mail-api:2.0.1-3  
javax-activation-api:1.2.0-6  
javax-mail-api:1.6.2-9  
jaxb:2.3.8-1  
jdk-tool:63.v62d2fd4b\_4793  
jenkins-design-language:1.27.1  
jersey2-api:2.38-1  
jjwt-api:0.11.5-77.v646c772fddb\_0  
job-import-plugin:3.6  
ldap:682.v7b\_544c9d1512  
leastload:3.0.0  
mailer:448.v5b\_97805e3767  
matrix-auth:3.1.6  
mina-sshd-api-common:2.9.2-50.va\_0e1f42659a\_a  
mina-sshd-api-core:2.9.2-50.va\_0e1f42659a\_a  
next-build-number:1.8  
okhttp-api:4.10.0-125.v3593b\_a\_f8c97b\_  
pam-auth:1.10  
pipeline-build-step:2.18.1  
pipeline-github-lib:38.v445716ea\_edda\_  
pipeline-graph-analysis:202.va\_d268e64deb\_3  
pipeline-groovy-lib:629.vb\_5627b\_ee2104  
pipeline-input-step:466.v6d0a\_5df34f81  
pipeline-milestone-step:111.v449306f708b\_7  
pipeline-model-api:2.2118.v31fd5b\_9944b\_5  
pipeline-model-definition:2.2118.v31fd5b\_9944b\_5  
pipeline-model-extensions:2.2118.v31fd5b\_9944b\_5  
pipeline-rest-api:2.31  
pipeline-stage-step:305.ve96d0205c1c6  
pipeline-stage-tags-metadata:2.2118.v31fd5b\_9944b\_5  
pipeline-stage-view:2.31  
plain-credentials:143.v1b\_df8b\_d3b\_e48  
popper2-api:2.11.6-2  
pubsub-light:1.17  
python:1.3  
resource-disposer:0.21  
rpmsign-plugin:0.5.1  
scm-api:676.v886669a\_199a\_a\_  
script-security:1369.v9b\_98a\_4e95b\_2d  
simple-theme-plugin:146.v0e67db\_a\_9052e  
snakeyaml-api:1.33-95.va\_b\_a\_e3e47b\_fa\_4  
ssh-credentials:305.v8f4381501156  
ssh-slaves:2.854.v7fd446b\_337c9  
sshd:3.275.v9e17c10f2571  
structs:324.va\_f5d6774f3a\_d  
timestamper:1.22  
token-macro:359.vb\_cde11682e0c  
trilead-api:2.84.v72119de229b\_7  
variant:59.vf075fe829ccb  
workflow-aggregator:590.v6a\_d052e5a\_a\_b\_5  
workflow-api:1291.v51fd2a\_625da\_7  
workflow-basic-steps:1010.vf7a\_b\_98e847c1  
workflow-cps:3618.v13db\_a\_21f0fcf  
workflow-durable-task-step:1234.v019404b\_3832a  
workflow-job:1316.vd2290d3341a\_f  
workflow-multibranch:733.v109046189126  
workflow-scm-step:400.v6b\_89a\_1317c9a\_  
workflow-step-api:639.v6eca\_cd8c04a\_a\_  
workflow-support:920.v59f71ce16f04  
yet-another-docker-plugin:0.2.0

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [January 16, 2025, 4:11pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/2 "2025-01-16T16:11:57Z")

</div>

You say they are NOT pipeline jobs? How are you defining the rpmbuild variable?

---

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 16, 2025, 4:38pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/3 "2025-01-16T16:38:06Z")

</div>

Maybe it’s a pipeline jobm I’m not 100% sure as I didn’t create them. The variable is defined inside a Shell/Execute command section as:

`rpmbuild --define "_topdir ${WORKSPACE}/rpmbuild" --define="release ${BUILD_NUMBER}" -ba rpmbuild/SPECS/vcre`

---

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 16, 2025, 4:41pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/4 "2025-01-16T16:41:08Z")

</div>

I think it’s a freestlr/general job, the Configure entries contain Build Step etc but no pipeline section

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [January 16, 2025, 4:50pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/5 "2025-01-16T16:50:05Z")

</div>

This should have never worked, each Shell/Execute Command is a separate invocation of the shell, which means the scoping does not carry over from one command section to the next.

---

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 16, 2025, 5:02pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/6 "2025-01-16T17:02:22Z")

</div>

Thanks, I figured it would be down to scoping somehow. I’m not sure how it used to manage to work…

Is there a way I can share variables between the shells. Can I simply dot source in a properties file.?

---

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 16, 2025, 5:11pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/7 "2025-01-16T17:11:03Z")

</div>

The variable values are currently written to `properties.txt`I’m not sure if that’s just for logging purposes or whether jenkins shells may inherit env vars from the txt file, perhaps?

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 16, 2025, 5:55pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/8 "2025-01-16T17:55:25Z")

</div>

I don’t see anywhere that you use `$rpmbuild` or an env variable with name `rpmbuild`  
It would help if you provide a screenshot of the job config (redact sensitive information) and the log of a failing job  
`rpmbuild` is btw a command that you have on certain linux distributions (e.g. readhat and suse) that allows to build rpm packages (installer packages). The package that provides this command might have been removed by your IT.

---

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 17, 2025, 3:31pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/9 "2025-01-17T15:31:30Z")

</div>

OK thanks, here’s a fresh example with some screenshots and logfiles and I’ve annotated the steps…

First, we have a build step which sets version and rpmtype into properties.txt. I don’t know if properties.txt has any special meaning in Jenkins or whether we’re just lpgging here…

 ![properties](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/7/7b16fe6cab9be24dec80c994a63909e9c6a93390.png)

Next we run rpmbuild in a separate command/execute shell block. I can’t add a screenshot because new users are limited on one screenshot, but here is the text from the command/exec shell:

rpmbuild --define “\_topdir {WORKSPACE}/rpmbuild" --define="release {BUILD\_NUMBER}” -ba rpmbuild/SPECS/${rpmtype}.spec

The issue is that ${rpmtype}. used to expand to ‘vcsync’ but now it’s an empty string. If it were just this one job, I’d say someone must have deleted some code that dot sourced properties.txt, but we have about 15 jobs that are all exhibiting the same behaviour. Maybe there’s a plugin that automativally inherits from properties.txt and it stopped wotking after a patch or something?

Here’s the relevant part of the console output from the job:

–log snip–

- cat properties.txt  
version = develop  
rpmtype = vcsync  
[vcsync-develop] $ /bin/sh -xe /tmp/jenkins4703385654598334318.sh
- rpmbuild --define ‘\_topdir /var/lib/jenkins/workspace/vcsync-develop/rpmbuild’ ‘–define=release 36’ -ba rpmbuild/SPECS/.spec  
error: failed to stat /var/lib/jenkins/workspace/vcsync-develop/rpmbuild/SPECS/.spec: No such file or directory  
–eonf of log snip—

The build fails because the rpmbuild command has been constructed with ‘/SPECS/.spec’ instead of ‘/SPECS/vcsync.spec’

TIA  
Duncan

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 17, 2025, 4:05pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/10 "2025-01-17T16:05:14Z")

</div>

It is possible to inject env variables between steps in freestyle jobs. But it requires an explicit setp from the [Environment Injector](https://plugins.jenkins.io/envinject/) plugin  
With the step `Inject environment variables` you can give a path to a properties file.  
But without this there is no way that a properties.txt is implicitly loaded

---

<div class="post-metadata">

**Author:** ![duncan-smith1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/duncan-smith1/32/12722_2.png) [@duncan-smith1](https://community.jenkins.io/u/duncan-smith1)\
**Post date:** [January 17, 2025, 4:38pm UTC](https://community.jenkins.io/t/variable-scoping-recently-broke-or-changed/25817/11 "2025-01-17T16:38:50Z")

</div>

Thanks for the info Markus. We must have had something like Environment Injector working not so long ago.I’ll look into it.
