title: Change environment variable when using Jenkins
body: <p>I'm trying to use Jenkins for running  python tests and creating coverage reports.</p>
  
  <p>I have compiled application that is bound with python - lets call it pythonX - that setts up environment for executing parts of that application. Now, when I want to run tests for some part of the code I can just run</p>
  
  <p><code>d:\my_app\sys\pythonX.exe -m pytest d:\user\repos\my_app\tests\unit</code></p>
  
  <p>and all works really nice because <code>pythonX</code> knows where everything is.</p>
  
  <p>For that I'm using</p>
  
  <pre><code>stage('Run tests') {
          steps {
              bat 'd:\\my_app\\sys\\pythonX.exe -m pytest d:\\user\\repos\\my_app\\tests\\unit'
          }
  }
  </code></pre>
  
  <p>.
  But there is a problem, this <code>pythonX</code> is running the tests on the code that is shipped with the application, so already built and all that. What I wan't is to run tests on the code that is still local.</p>
  
  <p>The <code>pythonX</code> adds a environment variable <code>PYTHONPATH</code> for specifying where the source code is but whenever I start the <code>pythonX.exe</code> via <code>bat</code> it changes whatever I've added before.</p>
  
  <p>What I've tried first is using the <code>withEnv</code> like so</p>
  
  <pre><code>stage('Run tests') {
          steps {
              withEnv(['PATH+PYTHONPATH=d:\\user\\repos\\my_app']){
                  bat 'd:\\my_app\\sys\\pythonX.exe -m pytest d:\\user\\repos\\my_app\\tests\\unit'
              }
          }
  }
  </code></pre>
  
  <p>but it doesn't help.</p>
  
  <p>What I've tried is else is setting up the environment, then changing the <code>PYTHONPATH</code> variable, and then running the tests via <code>pythonX</code> in existing environment.
  This is the code</p>
  
  <pre><code>stage('Run tests') {
          steps {
              bat '''
              d:\\my_app\\sys\\pythonX.exe  --debug=cmd
              set PYTHONPATH= d:\\user\\repos\\my_app;%PYTHONPATH%
              d:\\my_app\\sys\\pythonX.exe -m pytest d:\\user\\repos\\my_app\\tests\\unit
              '''
          }
  }
  </code></pre>
  
  <p>but this doesn't work. I presume that is overwrites the <code>PYTHONPATH</code> environment variable with it's own.
  Does anyone know how to overcome this?</p>