ERROR: Error fetching remote repo 'origin' , WARNING: CredentialId "PUBLIC_KEY" could not be found

Hey , I added my Private SSH (id_ed25519 )key to Jenkins, which it reads perfectly, but for some reason It isnt able to read the github SSH key (id_ed25519.pub is the PUBLIC_KEY here). It ALWAYS gives this error before build fails


My Jenkinsfile is

pipeline {

    agent any 

    stages {
        stage('Checkout Codebase'){
            steps{
                checkout scm: [$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[credentialsId: 'PUBLIC_KEY', url: 'git@github.com:ShivamTyagi12345/Kritagya-Repository-Monitor-slackbot.git']]] 
            }
        }

        stage('Build') {
            steps {
                echo 'Building Codebase'
            }
        }

        stage('Test'){
            steps {
                echo 'Running Tests on changes'
            }
        }
        
        stage('Deploy'){
            steps{
                echo 'Done!:tada:'
            }
        }
    }

    post {

        always {
            echo 'Sending Slack message'
            sh "go run main.go ${BUILD_URL} ${currentBuild.currentResult} ${BUILD_NUMBER} ${JOB_NAME} "
        }
    }
}

That message means that a Jenkins credential does not exist with the identifier PUBLIC_KEY. You either need to insert the identifier of the credential that you defined or create a credential and assign it the PUBLIC_KEY identifier.

The Pipeline snippet syntax generator will help you avoid making that type of mistake. If you generate the checkout scm step from the Pipeline snippet syntax generator, it will insert the correct credential ID for you.

If that 90 second video clip is not enough, you can refer to the documentation of the git plugin for more details and for an additional video.