Regarding this problem, I updated my JHipster-Application with scripted Jenkins pipeline and have now in Jenkinsfile
(partly following these hints):
[...]
def dockerImage
withEnv(["DOCKER_CREDS=credentials('myregistry-login')"]) {
stage('publish docker') {
sh "./mvnw -X -ntp jib:build"
}
}
with Jenkins global credentials myregistry-login
saved in my Jenkins-Server to my own docker registry v2 docker-container https://myregistry.mydomain.com
(domain changed for security reasons). I can successfully do a $ docker login myregistry.mydomain.com
(as well as docker login https://myregistry.mydomain.com
as well as docker login myregistry.mydomain.com:443
) from local bash with the user and password stored in myregistry-login
.
In pom.xml
(following these hints as well as this, this and this):
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<to>
<image>myregistry.mydomain.com:443/username/imagename</image>
<tags>
<tag>${maven.build.timestamp}</tag>
<tag>latest</tag>
</tags>
<auth>
<username>${env.DOCKER_CREDS_USR}</username>
<password>${env.DOCKER_CREDS_PSW}</password>
</auth>
</to>
<container>
<jvmFlags>
<jvmFlag>-Xms512m</jvmFlag>
<jvmFlag>-Xmx1G</jvmFlag>
<jvmFlag>-Xdebug</jvmFlag>
</jvmFlags>
<mainClass>de.myproject_name.MyApp</mainClass>
</container>
</configuration>
</plugin>
where username
, imagename
and de.myproject_name.MyApp
are placeholders here.
Unfortunately I get
[DEBUG] TIMING Retrieving registry credentials for myregistry.mydomain.com:443
[DEBUG] No credentials could be retrieved for registry myregistry.mydomain.com:443
[...]
[ERROR] I/O error for image [myregistry.mydomain.com:443/username/imagename]:
[ERROR] Connect to myregistry.mydomain.com:443 [myregistry.mydomain.com/xxx.xxx.xxx.xxx] failed: Connection refused (Connection refused)
[DEBUG] TIMED Authenticating push to myregistry.mydomain.com:443 : 460.0 ms
[DEBUG] TIMED Building and pushing image : 514.0 ms
[ERROR] I/O error for image [registry-1.docker.io/library/adoptopenjdk]:
[ERROR] Socket closed
So the withEnv
isn't forwarded to Maven and/or the jib-maven-plugin is not reading the <auth>
-Tag, right? What am I still doing wrong?
And why is there an I/O error to registry-1.docker.io
?