How to find a list of jobs that uses a specific credential.

1 minute readKnowledge base

Issue

I am cleaning up credentials but I want to know if there are any jobs that are already using a specific credential. How can I find all the jobs that use this credential?

Resolution

The simplest method is to go to Manage JenkinsManage Credentials and find the credential in question, and check under the field: This credential has been recorded as used in the following places:, as an alternative, you can search through the filesystem.

Take a note of the CREDENTIAL_ID of the credential you would like to search for. The CREDENTIAL_ID is a value that is either set manually or an auto-generated alphanumeric string.

two_credentials
Figure 1. CredentialList

Log into a server that has access to your JENKINS_HOME and run find JENKINS_HOME/jobs -name FILE.xml -exec grep -l YOUR_CREDENTIAL_ID {} \;.

Replace JENKINS_HOME and YOUR_CREDENTIAL_ID with the respective values.

For FILE.xml, you can search config.xml files if your pipelines are defined from the UI, or you can search your build.xml files as well.

ubuntu@hostname:~$ find /var/lib/cloudbees-core-cm/jobs -name config.xml -exec grep -l 'honeyisgreat' {} \;
/var/lib/cloudbees-core-cm/jobs/HoneyHive/config.xml
/var/lib/cloudbees-core-cm/jobs/BuzzBuzz/config.xml
ubuntu@hostname:~$ find /var/lib/cloudbees-core-cm/jobs -name build.xml -exec grep -l 'honeyisgreat' {} \;
/var/lib/cloudbees-core-cm/jobs/HoneyHive/builds/1/build.xml
/var/lib/cloudbees-core-cm/jobs/BuzzBuzz/builds/3/build.xml