Skip to content

Instantly share code, notes, and snippets.

@VMuliadi
Created February 7, 2024 09:35
Show Gist options
  • Save VMuliadi/32e6eace6d7a1f3aad66758e530e8a03 to your computer and use it in GitHub Desktop.
Save VMuliadi/32e6eace6d7a1f3aad66758e530e8a03 to your computer and use it in GitHub Desktop.
decrypt credentials files in jenkins
import com.cloudbees.plugins.credentials.*;
import com.cloudbees.plugins.credentials.domains.Domain;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
def jenkins_credentials_id = "my-jenkins-credentials-file-id"
SystemCredentialsProvider.getInstance().getCredentials().stream().
filter { cred -> cred instanceof FileCredentialsImpl }.
map { fileCred -> (FileCredentialsImpl) fileCred }.
filter { fileCred -> jenkins_credentials_id.equals( fileCred.id ) }.
forEach { fileCred ->
String s = new String( fileCred.getSecretBytes().getPlainData() )
println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment