Search code examples
dockerjenkinsjenkins-pipelineartifactory

How to push docker image in artifactory with token authentication via Jenkins?


We operate artifactory and jenkins for CI process. Now we use standard username/password credentials for login to artifactory. Want to use token for login. I generated token in artifactory and add it to Jenkins. Part of code Jenkins pipeline:

// Build a Docker image
stage ('Build a Docker image') {
        docker.withRegistry("https://${params.DOCKER_REGISTRY}", params.DOCKER_REGISTRY_CREDS) {
        def img = docker.build("${docker_tag}:${build_version}", "--build-arg VERSION=${params.DOCKER_BUILD_VERSION} -f ${dockerfile} ." )
        try {
                img.push() 
                docker_push_rmi(img, docker_tag, "${params.DOCKER_BUILD_VERSION}.latest")
                docker_push_rmi(img, docker_tag, "latest")
        } finally {
            sh "docker rmi ${docker_tag}:${build_version}"
        }
        }   
}

where DOCKER_REGISTRY_CREDS - username/password for artifactory login.

How I can convert it to token access?


Solution

  • Try using the token as a password and use the username of whoever created the token.