<p>Just avoid the <code>docker</code> DSL; it is incompatible with Declarative. Also avoid <code>script</code> blocks. Simply</p>

<pre class="lang-java prettyprint-override"><code>withDockerServer([uri: "tcp://&lt;my-docker-socket&gt;"]) {
  withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https://&lt;my-docker-registry&gt;/"]) {
    sh '''
      docker build -t whatever .
      docker push whatever
      # or better, put all this stuff into a versioned Bash/Python/etc. script
    '''
  }
}
</code></pre>

CC BY-SA 4.0
2018-05-18T13:42:24.803Z
2018-05-18T13:42:24.803Z
Jesse Glick
<p>There seems to be an <a href="https://issues.jenkins-ci.org/browse/JENKINS-43324" rel="nofollow noreferrer">open issue</a> at the moment. Another user experienced the same issue as well and added the following comment:</p>

<blockquote>
  <p>why is there a difference between node context and stage context</p>
</blockquote>

CC BY-SA 3.0
2017-09-27T10:07:22.947Z
2017-09-27T10:07:22.947Z
030
<p>You can try to use scripting syntax into the declarative pipeline. For some step there is no declarative syntax yet. I had the same problem trying to use the <code>docker</code> global variable as a step.</p>

<pre><code>stage ('Docker Build') {
  steps {
    // prepare docker build context
    sh "cp target/project.war ./tmp-docker-build-context"

    // Build and push image with Jenkins' docker-plugin
    script {
      withDockerServer([uri: "tcp://&lt;my-docker-socket&gt;"]) {
        withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https://&lt;my-docker-registry&gt;/"]) {
            // we give the image the same version as the .war package
            def image = docker.build("&lt;myDockerRegistry&gt;/&lt;myDockerProjectRepo&gt;:${branchVersion}", "--build-arg PACKAGE_VERSION=${branchVersion} ./tmp-docker-build-context")
            image.push()
        }
      }
    }
  }
}
</code></pre>

CC BY-SA 3.0
2017-09-28T12:45:17.113Z
2017-09-28T12:45:17.113Z
Marcel Dias
<p>It seems that the syntax that is used in the pipeline plugin is incompatible with Blueocean. It looks like that the syntax is different as blueocean uses a declarative pipeline.</p>

<p>Example</p>

<p><a href="http://fishi.devtail.io/weblog/2016/11/20/docker-build-pipeline-as-code-jenkins/" rel="noreferrer">http://fishi.devtail.io/weblog/2016/11/20/docker-build-pipeline-as-code-jenkins/</a></p>

<pre><code>  stage ('Docker Build') {
    // prepare docker build context
    sh "cp target/project.war ./tmp-docker-build-context"

    // Build and push image with Jenkins' docker-plugin
    withDockerServer([uri: "tcp://&lt;my-docker-socket&gt;"]) {
      withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https://&lt;my-docker-registry&gt;/"]) {
        // we give the image the same version as the .war package
        def image = docker.build("&lt;myDockerRegistry&gt;/&lt;myDockerProjectRepo&gt;:${branchVersion}", "--build-arg PACKAGE_VERSION=${branchVersion} ./tmp-docker-build-context")
        image.push()
      }   
    }
}
</code></pre>

<p>results in:</p>

<pre><code>WorkflowScript: 5: Unknown stage section "sh". Starting with version 0.5, steps in a stage must be in a steps block. @ line 5, column 1.
   stage ('Docker Build') {
   ^
</code></pre>

<p>Attempt to solve the issue</p>

<p>When a steps block was added the pipeline failed again:</p>

<pre><code>WorkflowScript: 13: Method calls on objects not allowed outside "script" blocks. @ line 13, column 13.
               docker.withRegistry
</code></pre>

CC BY-SA 3.0
2017-09-26T14:38:18.820Z
Maybe show examples of the 2 cases?
Dan Cornilescu
CC BY-SA 3.0
2017-09-26T14:49:15.253Z
@DanCornilescu updated
030
<jenkins-blueocean>
How to publish a docker image to a private docker registry using Jenkins' blueocean?
030
# How to publish a docker image to a private docker registry using Jenkins' blueocean?

(Asked by: username_0 on 2017-09-26)

It seems that the syntax that is used in the pipeline plugin is incompatible with Blueocean. It looks like that the syntax is different as blueocean uses a declarative pipeline.
Example
http://fishi.devtail.io/weblog/2016/11/20/docker-build-pipeline-as-code-jenkins/
  stage ('Docker Build') {
    // prepare docker build context
    sh "cp target/project.war ./tmp-docker-build-context"

    // Build and push image with Jenkins' docker-plugin
    withDockerServer([uri: "tcp://"]) {
      withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https:///"]) {
        // we give the image the same version as the .war package
        def image = docker.build("/:${branchVersion}", "--build-arg PACKAGE_VERSION=${branchVersion} ./tmp-docker-build-context")
        image.push()
      }   
    }
}

results in:
WorkflowScript: 5: Unknown stage section "sh". Starting with version 0.5, steps in a stage must be in a steps block. @ line 5, column 1.
   stage ('Docker Build') {
   ^

Attempt to solve the issue
When a steps block was added the pipeline failed again:
WorkflowScript: 13: Method calls on objects not allowed outside "script" blocks. @ line 13, column 13.
               docker.withRegistry

**Tags:** jenkins-blueocean

> **Comments:**
> **username_1**: Maybe show examples of the 2 cases?  
> **username_0**: @DanCornilescu updated  

---

## 3 answers

### Answer by username_3 on 2017-09-28. Score: 6 | Accepted answer

You can try to use scripting syntax into the declarative pipeline. For some step there is no declarative syntax yet. I had the same problem trying to use the docker global variable as a step.
stage ('Docker Build') {
  steps {
    // prepare docker build context
    sh "cp target/project.war ./tmp-docker-build-context"

    // Build and push image with Jenkins' docker-plugin
    script {
      withDockerServer([uri: "tcp://"]) {
        withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https:///"]) {
            // we give the image the same version as the .war package
            def image = docker.build("/:${branchVersion}", "--build-arg PACKAGE_VERSION=${branchVersion} ./tmp-docker-build-context")
            image.push()
        }
      }
    }
  }
}


---

### Answer by username_2 on 2018-05-18. Score: 3

Just avoid the docker DSL; it is incompatible with Declarative. Also avoid script blocks. Simply
withDockerServer([uri: "tcp://"]) {
  withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https:///"]) {
    sh '''
      docker build -t whatever .
      docker push whatever
      # or better, put all this stuff into a versioned Bash/Python/etc. script
    '''
  }
}


---

### Answer by username_0 on 2017-09-27. Score: 1

There seems to be an [open issue](https://issues.jenkins-ci.org/browse/JENKINS-43324) at the moment. Another user experienced the same issue as well and added the following comment:

> why is there a difference between node context and stage context


---

