Pulling docker image in jenkins with using declarative Jenkinsfile

Solution 1:

You need to add the registry credentials in the credentials section of the Jenkins server. You also should ensure this pipeline has permissions to access those credentials. After completing that task, you can access the credentials in the agent directive like:

agent {
  docker {
    image                 'node:16-stretch'
    reuseNode             true
    registryUrl           'https://registry-1.docker.io'
    registryCredentialsId 'myRegistryCredentials'
  }
}

where myRegistryCredentials is the name of the credentials you added for the registry.