title: Using contains with Jenkins expression and env var
body: <p>I am trying to create a <code>Jenkinsfile</code> to handle different steps in prod vs dev environments. I was attempting to use the <a href="https://jenkins.io/doc/book/pipeline/syntax/#when" rel="nofollow noreferrer"><code>anyOf</code> pattern with an <code>expression</code></a> that checks the <code>JOB_URL</code> environmental variable to determine which build server/build instruction to follow.</p>
  
  <p>Jenkinsfile ends up looking something like the below:</p>
  
  <pre><code>stage('In Prod') {
      when {
          allOf {
              expression { params.P1 == 'x' }
              expression { params.P2 == 'y' }
              expression { env.JOB_URL.contains('prod_server.com') }
          }
      }
      ...
  }
  stage('In Dev') {
      when {
          allOf {
              expression { params.P1 == 'x' }
              expression { params.P2 == 'y' }
              expression { env.JOB_URL.contains('dev_server.com') }
          }
      }
      ...
  }
  </code></pre>
  
  <p>Expected Behavior:</p>
  
  <ul>
  <li>In Dev -> run <code>In Dev</code> step</li>
  <li>In Prod -> run <code>In Prod</code> step</li>
  </ul>
  
  <p>Actual Behavior:</p>
  
  <ul>
  <li>In Dev -> run <code>In Prod</code> AND <code>In Dev</code> step</li>
  <li>In Prod -> run <code>In Prod</code> step</li>
  </ul>
  
  <p>Yes, I have checked to make sure that <code>JOB_URL</code> on the <code>dev</code> does not contain <code>prod_server.com</code>.</p>
  
  <p>I have also tried <code>!env.JOB_URL.contains('dev_server.com')</code> as an additional expression for the <code>prod</code> step with the same result.</p>
  
  <p>I only know enough <code>groovy</code> to get through Jenkins, and am somewhat new to Jenkins pipeline syntax, so maybe I've misunderstood the behavior here, but from what I understand from the Jenkins <code>expression</code> documentation:</p>
  
  <blockquote>
    <p>when returning strings from your expressions they must be
    converted to booleans or return null to evaluate to false. Simply
    returning "0" or "false" will still evaluate to "true".</p>
  </blockquote>
  
  <p>And as a sanity check, I confirmed that the <code>groovy</code> documentation says <a href="http://docs.groovy-lang.org/docs/groovy-1.7.3/html/groovy-jdk/java/lang/String.html#contains(java.lang.String)" rel="nofollow noreferrer"><code>contains</code> should be returning a <code>boolean</code></a>.</p>