diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 253cabce..9a3a9d66 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -316,10 +316,10 @@ class Wget(FetchMethod):
         # to scope the changes to the build_opener request, which is when the
         # environment lookups happen.
         newenv = {}
+        origenv = d.getVar("BB_ORIGENV")
         for name in bb.fetch2.FETCH_EXPORT_VARS:
             value = d.getVar(name)
             if not value:
-                origenv = d.getVar("BB_ORIGENV")
                 if origenv:
                     value = origenv.getVar(name)
             if value:
