2424
2525package org .jenkinsci .plugins .docker .commons .impl ;
2626
27- import java .io .ByteArrayInputStream ;
2827import java .io .IOException ;
2928import java .net .URL ;
3029import java .nio .charset .StandardCharsets ;
@@ -52,7 +51,7 @@ public class RegistryKeyMaterialFactory extends KeyMaterialFactory {
5251
5352 private static final String DOCKER_CONFIG_FILENAME = "config.json" ;
5453 private static final String [] BLACKLISTED_PROPERTIES = { "auths" , "credsStore" };
55-
54+
5655 protected static final String DOCKER_REGISTRY_HOST_ONLY = "DOCKER_REGISTRY_HOST_ONLY" ;
5756
5857 private final @ NonNull String username ;
@@ -97,9 +96,10 @@ public KeyMaterial materialize() throws IOException, InterruptedException {
9796 }
9897
9998 try {
99+ // TODO on Docker 17.07+ use --password-stdin
100100 EnvVars envWithConfig = new EnvVars (env );
101101 envWithConfig .put ("DOCKER_CONFIG" , dockerConfig .getRemote ());
102- if (launcher .launch ().cmds (new ArgumentListBuilder (dockerExecutable , "login" , "-u" , username , "--password-stdin " ).add (registry ())).envs (envWithConfig ). stdin ( new ByteArrayInputStream ( password . getBytes ( "UTF-8" )) ).stdout (listener ).join () != 0 ) {
102+ if (launcher .launch ().cmds (new ArgumentListBuilder (dockerExecutable , "login" , "-u" , username , "-p " ).add (password , true ). add ( registry ())).envs (envWithConfig ).stdout (listener ).join () != 0 ) {
103103 throw new AbortException ("docker login failed" );
104104 }
105105 } catch (IOException | InterruptedException x ) {
@@ -112,12 +112,12 @@ public KeyMaterial materialize() throws IOException, InterruptedException {
112112 }
113113 return new RegistryKeyMaterial (dockerConfig , new EnvVars ("DOCKER_CONFIG" , dockerConfig .getRemote ()));
114114 }
115-
115+
116116 protected String registry () {
117117 if (dockerExecutable .endsWith ("podman" ) || Boolean .parseBoolean (env .get (DOCKER_REGISTRY_HOST_ONLY , "false" ))) {
118118 return endpoint .getAuthority ();
119119 }
120-
120+
121121 return endpoint .toString ();
122122 }
123123
0 commit comments