<p>Try to chain <code>withRegistry</code> like this:</p>

<pre class="lang-java prettyprint-override"><code>docker.withRegistry('https://registry:10500', 'credentials-id') {
    docker.withRegistry('https://registry:10501', 'credentials-id') {
        docker.build(imageToBuild.getName(), '-f ' + imageToBuild.tag + '.Dockerfile .').push();
    }
}
</code></pre>

CC BY-SA 4.0
2019-11-07T18:40:51.823Z
Sadly this doesn't have any effect. It doesn't even give me a different message. Just seems to treat it the exact same way as before. Like the first "withRegistry" does not have any effect.
Worp
CC BY-SA 4.0
2019-11-05T18:39:47.597Z
2019-11-05T18:39:47.597Z
Hedi Nasr
<p>I have two endpoints for my registry (Nexus OSS):</p>

<p>Endpoint 10500 to pull images from.</p>

<p>And Endpoint 10501 to push images to.</p>

<p>(I can go into detail what the idea is and why we think Nexus requires this if need be. I might have Nexus configured wrongly after all. But I am currently thinking it's correct.)</p>

<p>Jenkinsfile has:</p>

<pre><code>docker.withRegistry(myRegistry:10501, 'nexus_jenkins_user') {
    docker.build(imageToBuild.getName(), '-f ' + imageToBuild.tag + '.Dockerfile .').push();
}
</code></pre>

<p>Dockerfile has</p>

<pre><code>FROM myRegistry:10500/myNamespace/core:latest
...
</code></pre>

<p>Jenkins execution reports the following error:</p>

<pre><code>docker build -t myNamespace/php:php.7.2 -f php.7.2.Dockerfile .

Sending build context to Docker daemon   80.9kB

...

Step 1/7 : FROM myRegistry:10500/myNamespace/core:latest

Get https://myRegistry:10500/v2/myNamespace/core/manifests/latest: no basic auth credentials

script returned exit code 1
</code></pre>

<p>This seems obvious as the "withRegistry" directive above has the 10501 endpoint, so there would be no authentication for the 10500 endpoint here.</p>

<p>The challenge:
I need to be able to pull the core image (through 10500) but push the finished image to 10501.</p>

<p>What would my Jenkinsfile need to look like to achieve this?</p>

<p>This should theoretically be a common problem for companies utilizing Nexus OSS as they will have two endpoints as well. (Assuming I am correct about Nexus requiring two endpoints if a hosted repo and a proxy repo are being used).</p>

<p><strong>edit</strong>
To provide some help for understanding: If I specify</p>

<pre><code>FROM myRegistry:10501/myNamespace/core:latest
</code></pre>

<p>in my Dockerfile, authentication will work as "withRegistry" and the Dockerfile's FROM directive are set to the same endpoint.</p>

<p>But I want all pulling actions to go through 10500. If, for example, I would use an image from Docker Hub, 10500 would pull it from Hub, cache it and deliver it back to me, where 10501 would not. So 10500 needs to be used for all pulling.</p>

<jenkins><jenkinsfile><nexus><docker-registry>
Jenkinsfile: Pull image from registry endpoint A, push built image to registry endpoint B
Worp
# Jenkinsfile: Pull image from registry endpoint A, push built image to registry endpoint B

(Asked by: username_0 on 2019-11-05)

I have two endpoints for my registry (Nexus OSS):
Endpoint 10500 to pull images from.
And Endpoint 10501 to push images to.
(I can go into detail what the idea is and why we think Nexus requires this if need be. I might have Nexus configured wrongly after all. But I am currently thinking it's correct.)
Jenkinsfile has:
docker.withRegistry(myRegistry:10501, 'nexus_jenkins_user') {
    docker.build(imageToBuild.getName(), '-f ' + imageToBuild.tag + '.Dockerfile .').push();
}

Dockerfile has
FROM myRegistry:10500/myNamespace/core:latest
...

Jenkins execution reports the following error:
docker build -t myNamespace/php:php.7.2 -f php.7.2.Dockerfile .

Sending build context to Docker daemon   80.9kB

...

Step 1/7 : FROM myRegistry:10500/myNamespace/core:latest

Get https://myRegistry:10500/v2/myNamespace/core/manifests/latest: no basic auth credentials

script returned exit code 1

This seems obvious as the "withRegistry" directive above has the 10501 endpoint, so there would be no authentication for the 10500 endpoint here.
The challenge:
I need to be able to pull the core image (through 10500) but push the finished image to 10501.
What would my Jenkinsfile need to look like to achieve this?
This should theoretically be a common problem for companies utilizing Nexus OSS as they will have two endpoints as well. (Assuming I am correct about Nexus requiring two endpoints if a hosted repo and a proxy repo are being used).
edit
To provide some help for understanding: If I specify
FROM myRegistry:10501/myNamespace/core:latest

in my Dockerfile, authentication will work as "withRegistry" and the Dockerfile's FROM directive are set to the same endpoint.
But I want all pulling actions to go through 10500. If, for example, I would use an image from Docker Hub, 10500 would pull it from Hub, cache it and deliver it back to me, where 10501 would not. So 10500 needs to be used for all pulling.

**Tags:** jenkins, jenkinsfile, nexus, docker-registry


---

## 1 answers

### Answer by username_1 on 2019-11-05. Score: 1

Try to chain withRegistry like this:
docker.withRegistry('https://registry:10500', 'credentials-id') {
    docker.withRegistry('https://registry:10501', 'credentials-id') {
        docker.build(imageToBuild.getName(), '-f ' + imageToBuild.tag + '.Dockerfile .').push();
    }
}

> **Comments:**
> **username_0**: Sadly this doesn't have any effect. It doesn't even give me a different message. Just seems to treat it the exact same way as before. Like the first "withRegistry" does not have any effect.  

---

