Forked from briceburg/print-jenkins-secret-file-contents.groovy
          
        
    
          Created
          December 14, 2022 22:12 
        
      - 
      
- 
        Save saquibtmf/d3807ad2cca66455a09f6a7527c2478c to your computer and use it in GitHub Desktop. 
    Print content of secret files from the Jenkins Credentials Store
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import com.cloudbees.plugins.credentials.*; | |
| import com.cloudbees.plugins.credentials.domains.Domain; | |
| import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl; | |
| // | |
| // modify fileName to match the filename of the secret(s) you want to print. | |
| // (ID would probably be more helpful... yay stack overflow copy pasta) | |
| // alternatively comment out the filter [line 15] to dump all secret files. | |
| // | |
| def fileName = "secrets.env" | |
| SystemCredentialsProvider.getInstance().getCredentials().stream(). | |
| filter { cred -> cred instanceof FileCredentialsImpl }. | |
| map { fileCred -> (FileCredentialsImpl) fileCred }. | |
| filter { fileCred -> fileName.equals( fileCred.getFileName() ) }. | |
| forEach { fileCred -> | |
| String s = new String( fileCred.getSecretBytes().getPlainData() ) | |
| println "" | |
| println "XXXXXX BEGIN a secret file with id=" + fileCred.getId() + " fileName=" + fileName + " XXXXXXXXXXXX" | |
| println s | |
| println "" | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment