# How to read Windows environment variable in script console?

**URL:** <https://community.jenkins.io/t/how-to-read-windows-environment-variable-in-script-console/2141>\
**Category:** Using Jenkins\
**Tags:** question\
**Created:** [April 18, 2022, 3:21pm UTC](https://community.jenkins.io/t/how-to-read-windows-environment-variable-in-script-console/2141 "2022-04-18T15:21:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsabiston](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/bsabiston/32/1028_2.png) [@bsabiston](https://community.jenkins.io/u/bsabiston)\
**Post date:** [April 18, 2022, 3:21pm UTC](https://community.jenkins.io/t/how-to-read-windows-environment-variable-in-script-console/2141/1 "2022-04-18T15:21:56Z")

</div>

It’s been surprisingly difficult to find a simple straightforward answer to this question. I know how to SET environment variables, but if I have a Windows environment variable already defined when I start Jenkins, can I reference that in the script console?

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [April 18, 2022, 6:43pm UTC](https://community.jenkins.io/t/how-to-read-windows-environment-variable-in-script-console/2141/2 "2022-04-18T18:43:58Z")

</div>

by script console do you mean $JENKINS\_URL/script? You should be able to use straight up groovy, so `System.getenv('FOO')`

If by script console you mean jenkinsfile/pipeline. By default system env variables are not exposed, you generally want to set them up in the agent configuration screen.

---

<div class="post-metadata">

**Author:** ![bsabiston](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/bsabiston/32/1028_2.png) [@bsabiston](https://community.jenkins.io/u/bsabiston)\
**Post date:** [April 19, 2022, 2:40pm UTC](https://community.jenkins.io/t/how-to-read-windows-environment-variable-in-script-console/2141/5 "2022-04-19T14:40:50Z")

</div>

OK - thank you for the reply. Turns out `System.getenv('FOO')` is all I needed, thanks!
