title: How to do simple if-statements inside a declarative pipeline in Jenkins
body: <p>I'm trying to convert my Scripted pipeline to a Declarative Pipeline.
  Wondering how to do a simple if-statement inside a <code>steps {}</code> block.</p>
  
  <pre><code>    stage ('Deploy to Docker') {
          steps {
              parallel (
                  "instance1" : {
                      environment {
                          containerId = sh(script: "docker ps --quiet --filter name=${fullDockerImageName}", returnStdout: true).trim()
                      }
                      steps {
                          if (containerId.isEmpty()) {
                              docker.image('some/image').run("--name ${fullDockerImageName}")
                          }
                      }
                  }
              )
          }
     }
  </code></pre>
  
  <p>This causes the following Exception:</p>
  
  <pre><code>WorkflowScript: 201: Expected a step @ line 201, column 29.
                             if (containerId.isEmpty()) {
  </code></pre>
  
  <p>Since I'm not allowed to do a simple <code>if(..)</code> inside a <code>steps {}</code> block, any idea on how to do this?</p>
  
  <p>It doesn't seem to make sense to make this a full stage with a <code>when {}</code>, since there are more steps that happens in a simple stage (starting a stopped container if it exists, etc).</p>
  
  <p>What's the best way to do a simple if?</p>