I made a multibranch pipeline project in Jenkins. I need to use two repositories and both need credentials.
I created a Jenkinsfile in repository1:
n
I've had the exact same issue: checkout using credentials in a freestyle project works fine, checkout in a shell (as the jenkins user) works fine, and checkout in the pipeline fails. I've updated Jenkins + plugins to the latest version.
I finally managed to get it to work by placing the correct key in /var/lib/jenkins/.ssh/id_rsa. It looks like the GitSCM plugin completely ignores the provided credentialsId, and just uses the key in /var/lib/jenkins/.ssh/id_rsa. I generated a keypair without passphrase for this.
It is a workaround, and I suspect that GitSCM has a bug, but at least you can use the pipeline plugin.