public void execInternal(@Nonnull final DockerClient client, @Nonnull final String imageName, TaskListener listener)
            throws IOException {
        PrintStream llog = listener.getLogger();

        if (shouldPullImage(client, imageName)) {
            LOG.info("Pulling image '{}'. This may take awhile...", imageName);
            llog.println(String.format("Pulling image '%s'. This may take awhile...", imageName));

            long startTime = System.currentTimeMillis();
            final PullImageCmd pullImageCmd = client.pullImageCmd(imageName);

//            final AuthConfig authConfig = pullImageCmd.getAuthConfig();
            for (DockerRegistryCredential cred : getRegistriesCreds()) {
                // hostname requirements?
                Credentials credentials = lookupSystemCredentials(cred.getCredentialsId());
//                final String registryAddr = cred.getRegistryAddr();
                if (credentials instanceof DockerRegistryAuthCredentials) {
                    final DockerRegistryAuthCredentials authCredentials = (DockerRegistryAuthCredentials) credentials;
                    // TODO update docker-java for multiple entries
                    pullImageCmd.withAuthConfig(authCredentials.getAuthConfig());
                }
            }
            // Deprecated
            if (StringUtils.isNotBlank(credentialsId)) {
                // hostname requirements?
                Credentials credentials = lookupSystemCredentials(credentialsId);
                if (credentials instanceof DockerRegistryAuthCredentials) {
                    final DockerRegistryAuthCredentials authCredentials = (DockerRegistryAuthCredentials) credentials;
                    pullImageCmd.withAuthConfig(authCredentials.getAuthConfig());
                }
            }

            try {
                pullImageCmd
                        .exec(new DockerPullImageListenerLogger(listener))
                        .awaitSuccess();
            } catch (DockerClientException exception) {
                String exMsg = exception.getMessage();
                if (exMsg.contains("Could not pull image: Digest:") ||
                        exMsg.contains(": downloaded")) {
                    try {
                        client.inspectImageCmd(imageName).exec();
                    } catch (NotFoundException notFoundEx) {
                        throw exception;
                    }
                } else {
                    throw exception;
                }
            }

            long pullTime = System.currentTimeMillis() - startTime;
            LOG.info("Finished pulling image '{}', took {} ms", imageName, pullTime);
            llog.println(String.format("Finished pulling image '%s', took %d ms", imageName, pullTime));
        }
    }
public void execInternal ( @ Nonnull final DockerClient client , @ Nonnull final String imageName , TaskListener listener ) throws IOException { PrintStream llog = listener . getLogger ( ) ; if ( shouldPullImage ( client , imageName ) ) { LOG . info ( "Pulling image '{}'. This may take awhile..." , imageName ) ; llog . println ( String . format ( "Pulling image '%s'. This may take awhile..." , imageName ) ) ; long startTime = System . currentTimeMillis ( ) ; final PullImageCmd pullImageCmd = client . pullImageCmd ( imageName ) ; for ( DockerRegistryCredential cred : getRegistriesCreds ( ) ) { Credentials credentials = lookupSystemCredentials ( cred . getCredentialsId ( ) ) ; if ( credentials instanceof DockerRegistryAuthCredentials ) { final DockerRegistryAuthCredentials authCredentials = ( DockerRegistryAuthCredentials ) credentials ; pullImageCmd . withAuthConfig ( authCredentials . getAuthConfig ( ) ) ; } } if ( StringUtils . isNotBlank ( credentialsId ) ) { Credentials credentials = lookupSystemCredentials ( credentialsId ) ; if ( credentials instanceof DockerRegistryAuthCredentials ) { final DockerRegistryAuthCredentials authCredentials = ( DockerRegistryAuthCredentials ) credentials ; pullImageCmd . withAuthConfig ( authCredentials . getAuthConfig ( ) ) ; } } try { pullImageCmd . exec ( new DockerPullImageListenerLogger ( listener ) ) . awaitSuccess ( ) ; } catch ( DockerClientException exception ) { String exMsg = exception . getMessage ( ) ; if ( exMsg . contains ( "Could not pull image: Digest:" ) || exMsg . contains ( ": downloaded" ) ) { try { client . inspectImageCmd ( imageName ) . exec ( ) ; } catch ( NotFoundException notFoundEx ) { throw exception ; } } else { throw exception ; } } long pullTime = System . currentTimeMillis ( ) - startTime ; LOG . info ( "Finished pulling image '{}', took {} ms" , imageName , pullTime ) ; llog . println ( String . format ( "Finished pulling image '%s', took %d ms" , imageName , pullTime ) ) ; } }
Action around image with defined configuration