젠킨스에 크레덴셜로 저장된 비밀번호 등의 값을 알아내고 싶은 경우 두가지 방법이 있다
- job을 만들어서 아래 파이프라인 스크립트를 수행
https://www.codurance.com/publications/2019/05/30/accessing-and-dumping-jenkins-credentials 내용을 기반으로 좀더 간단하게 작성했음
pipeline {
agent any
stages {
stage('sshUserPrivateKey') {
steps {
script {
withCredentials([
sshUserPrivateKey(
credentialsId: 'gerrit',
keyFileVariable: 'keyFile',
passphraseVariable: 'passphrase',
usernameVariable: 'username'
)
]) {
print 'keyFile=' + keyFile
print 'passphrase=' + passphrase
print 'username=' + username
print 'keyFile.collect { it }=' + keyFile.collect { it }
print 'passphrase.collect { it }=' + passphrase.collect { it }
print 'username.collect { it }=' + username.collect { it }
print 'keyFileContent=' + readFile(keyFile)
}
}
}
}
}
}
- jenkins 서버에 직접 ssh 접속이 가능하다면 /var/jenkins_home/credential.xml 파일을 오픈 (젠킨스 설치 경로는 설치 방식에 따라 조금씩 다를 수 있음)
파일 안에서 원하는 password 또는 credential을 찾음. (암호화되어 저장되어있는 경우 {XXXXX==}
와 같은 식으로 표현되어있음)
https://your.jenkins.com/script 경로에 접근한 후에 해당 창에 아래와 같이 원하는 암호화된 값을 넣고 실행하면 복호화된 값이 출력됨
println(hudson.util.Secret.decrypt("{XXXXX==}"))