title: Using a dockerfile with Jenkins Scripted Pipeline Syntax
body: <p>Using <a href="https://jenkins.io/doc/book/pipeline/syntax/#compare" rel="noreferrer">Jenkins Declarative Pipeline</a>, one can easily specify a Dockerfile, agent label, build args and run args as follows:</p>
  <p><em><strong>Jenkinsfile (Declarative Pipeline)</strong></em></p>
  <pre><code>agent {
      dockerfile {
          dir './path/to/dockerfile'
          label 'my-label'
          additionalBuildArgs  '--build-arg version=1.0'
          args '-v /tmp:/tmp'
      }
  }
  </code></pre>
  <p>I am trying to achieve the same using the scripted pipeline syntax. I found a way to pass the agent label and run args, but was unable to to pass the <strong>directory</strong> and <strong>build args</strong>. Ideally, I would write something like this (label and run args are already working):</p>
  <p><em><strong>Jenkinsfile (Scripted Pipeline)</strong></em></p>
  <pre><code>node (&quot;my-label&quot;){
      docker.dockerfile(
          dir: './path/to/dockerfile',
          additionalBuildArgs:'--build-arg version=1.0'
      ).inside('-v /tmp:/tmp') {
          \\ add stages here
      }
  }
  </code></pre>
  <hr />
  <p>The <a href="https://jenkins.io/doc/book/pipeline/docker/" rel="noreferrer">documentation</a> shows how this can be done using an existing docker image, i.e., with the <code>image</code> directive in the pipeline.</p>
  <p><em><strong>Jenkinsfile (Declarative Pipeline)</strong></em></p>
  <pre><code>pipeline {
      agent {
          docker { image 'node:7-alpine' }
      }
      stage('Test') {
          //...
      }
  }
  </code></pre>
  <p><em><strong>Jenkinsfile (Scripted Pipeline)</strong></em></p>
  <pre><code>node {
      docker.image('node:7-alpine').inside {
          stage('Test') {
              //...
          }
      }
  }
  </code></pre>
  <hr />
  <p>However, the scripted pipeline syntax for the <code>dockerfile</code> directive is missing.
  The workaround I am using at the moment is building the image myself.</p>
  <pre><code>node (&quot;my-label&quot;){
      def testImage = docker.build(
          &quot;test-image&quot;,
          &quot;./path/to/dockerfile&quot;,
          &quot;--build-arg v1.0&quot;
      )
  
      testImage.inside('-v /tmp:/tmp') {
          sh 'echo test'
      }
  }
  </code></pre>
  <p>Any help is much appreciated!</p>