How to Fix Credential Not Found Error in Jenkins
credential not found error in Jenkins happens when the pipeline or job tries to use a credential ID that does not exist or is not accessible. To fix it, verify the credential ID in Jenkins credentials store and ensure your pipeline references the exact ID with proper permissions.Why This Happens
This error occurs because Jenkins cannot find the credential with the specified ID in its credentials store. It may be due to a typo in the credential ID, the credential not being created, or the credential being stored in a different domain or folder than where the job runs.
pipeline {
agent any
stages {
stage('Example') {
steps {
withCredentials([usernamePassword(credentialsId: 'wrong-id', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $USER'
}
}
}
}
}The Fix
Check the Jenkins credentials store to find the correct credential ID. Update your pipeline or job configuration to use this exact ID. Also, ensure the credential is accessible in the current folder or global domain where the job runs.
pipeline {
agent any
stages {
stage('Example') {
steps {
withCredentials([usernamePassword(credentialsId: 'correct-id', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $USER'
}
}
}
}
}Prevention
Always create and verify credentials in Jenkins before referencing them in pipelines. Use consistent naming conventions for credential IDs. Avoid hardcoding credentials; instead, use Jenkins credentials store. Regularly audit credential permissions and scope to ensure jobs can access them.
Related Errors
- Access Denied to Credentials: Happens if the job lacks permission to use the credential. Fix by adjusting folder/job permissions.
- Credential ID Typo: Misspelled credential ID causes not found error. Double-check spelling.
- Credential Scope Issues: Credentials created in a folder are not visible globally. Create credentials in the correct scope.