Agustin Castro
Agustin Castro

Reputation: 459

Pushing docker image through jenkins

I'm pushing docker image through Jenkins pipeline, but I'm getting the following error:

ERROR: Could not find credentials matching gcr:["google-container-registry"]

I tried with:

gcr:["google-container-registry"]
gcr:[google-container-registry]
gcr:google-container-registry
google-container-registry

but none of them worked.

In the global credentials I have:

NAME: google-container-registry

KIND: Google Service Account from private key

DESCRIPTION: A Google robot account for accessing Google APIs and services.

Upvotes: 4

Views: 5062

Answers (3)

Tiago Medici
Tiago Medici

Reputation: 2194

Go to Jenkins → Manage Jenkins → Manage Plugins and install plugins: Google Container Registry Google OAuth Credentials CloudBees Docker Build and Publish

Jenkins → Credentials → Global Credentials → Add Credentials, choose desired ‘Project Name’ and upload JSON file

enter image description here

Jenkinsfile:

 stage('Deploy Image') {
                steps{
                    script {
                        docker.withRegistry( 'https://gcr.io', "gcr:${ID}" ) {
                            dockerImage.push("$BUILD_NUMBER")
                            dockerImage.push('latest')
                        }
                    }
                }
            }

Upvotes: 1

VictorB
VictorB

Reputation: 156

check if you have https://plugins.jenkins.io/google-container-registry-auth/ plugin installed.

After plugin installed use gcr:credential-id synthax

Example:

stage("docker build"){
    Img = docker.build(
        "gcpProjectId/imageName:imageTag",
        "-f Dockerfile ."
    )
}

stage("docker push") {
    docker.withRegistry('https://gcr.io', "gcr:credential-id") {
        Img.push("imageTag")
    }
}

Upvotes: 0

gmc
gmc

Reputation: 3990

The proper syntax is the following (provided your gcr credentials id is 'google-container-registry'):

docker.withRegistry("https://gcr.io", "gcr:google-container-registry") {
  sh "docker push [your_image]"
}

Upvotes: 4

Related Questions