# Access environment variable in jenkinsfile which is set in python

**URL:** <https://community.jenkins.io/t/access-environment-variable-in-jenkinsfile-which-is-set-in-python/8227>\
**Category:** Ask a question\
**Tags:** jenkinsfile, python\
**Created:** [June 28, 2023, 1:07pm UTC](https://community.jenkins.io/t/access-environment-variable-in-jenkinsfile-which-is-set-in-python/8227 "2023-06-28T13:07:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david39](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david39](https://community.jenkins.io/u/david39)\
**Post date:** [June 28, 2023, 1:07pm UTC](https://community.jenkins.io/t/access-environment-variable-in-jenkinsfile-which-is-set-in-python/8227/1 "2023-06-28T13:07:22Z")

</div>

I have set the value of environment variable in python.

```auto
os.environ['MY_VAR']=str(len(mylist))

```

in jenkins file i want to access its value.

```auto
script
{
echo "${MY_VAR}"
if ("${MY_VAR}" != "0" )
{ email = sh (script:
"""#!/bin/bash -e
""")

}
}

```

But it is showing null value.

---

<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:** [June 28, 2023, 1:41pm UTC](https://community.jenkins.io/t/access-environment-variable-in-jenkinsfile-which-is-set-in-python/8227/2 "2023-06-28T13:41:02Z")

</div>

environment variables are process specific and only visible within the process where it is set and its child processes. You can’t set an environment variable and refer to it in the parent process or other processes

---

<div class="post-metadata">

**Author:** ![daotoan-hd](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/daotoan-hd/32/4716_2.png) [@daotoan-hd](https://community.jenkins.io/u/daotoan-hd)\
**Post date:** [July 8, 2023, 9:41am UTC](https://community.jenkins.io/t/access-environment-variable-in-jenkinsfile-which-is-set-in-python/8227/3 "2023-07-08T09:41:58Z")

</div>

You could try another approach like:  
Write the value into file with your python code.  
And read the file on your pipeline
