title: How can Java code read a Jenkins Global credentials during Jenkins build?
body: <p>I have a Java project that builds on Jenkins. This code needs a Secret file (<strong>.pem format</strong>) to run. I can't save the file in the Java project itself (security reasons). </p>
  
  <p>The file format is key_v2-XXXXX.pem and contents are </p>
  
  <pre><code>-----BEGIN PRIVATE KEY-----
  XXX
  XXXX
  -----END PRIVATE KEY-----
  </code></pre>
  
  <p>Currently, the Java code is accessing the Secret file present in the Local. So the local build is fine. 
  But when this code is executed on Jenkins, the build fails because it can't find the local file or the file is not accessible to Jenkins. </p>
  
  <p>I've added the <strong>Secret File</strong> as a Global Credential (unrestricted) in Jenkins. (Reference - <a href="https://jenkins.io/doc/book/using/using-credentials/" rel="nofollow noreferrer">https://jenkins.io/doc/book/using/using-credentials/</a>)</p>
  
  <p>I need to find a way for the <strong>Java code</strong> to access this Secret file(stored in Jenkins) while running the Jenkins build. </p>
  
  <p>Or Is there any other way to handle this situation?</p>