'Jenkins git error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

I have Jenkins pipeline which uses a valid SSH key via the Credentials Binding Plugin. I have a script step which calls "git clone <repo_name>":

script {
  withCredentials([sshUserPrivateKey(credentialsId: '<cred_name>', keyFileVariable: '<file_name>', usernameVariable: '<user_name>')]) {
  sh """ 
    git clone <SSH_git_reponame>
  """

And it throws an error:

  Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
  fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.

Previously, before Jenkins plugins updated it worked fine. Also, I've tried to pull via https (instead of git) and it works.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source