我已经为Jenkins添加了SSH凭证.
不幸的是,我忘记了SSH密码,现在想从Jenkins的凭证存档中获取它,该存档位于${JENKINS_HOME}/credentials.xml.
这XML文档似乎在XML标签加密凭证<passphrase>或<password>.
如何检索明文密码?
Abd*_*ull 138
通过访问打开Jenkins的安装脚本控制台http(s)://${JENKINS_ADDRESS}/script.
在那里,执行以下Groovy脚本:
println( hudson.util.Secret.decrypt("${ENCRYPTED_PASSPHRASE_OR_PASSWORD}") )
Run Code Online (Sandbox Code Playgroud)
其中,${ENCRYPTED_PASSPHRASE_OR_PASSWORD}是的加密的内容<password>或<passphrase>你正在寻找的XML元素.
Bar*_*baz 12
转到管理 Jenkins -> 脚本控制台并运行以下代码:
import java.nio.charset.StandardCharsets;
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.Credentials.class
)
for (c in creds) {
println(c.id)
if (c.properties.description) {
println(" description: " + c.description)
}
if (c.properties.username) {
println(" username: " + c.username)
}
if (c.properties.password) {
println(" password: " + c.password)
}
if (c.properties.passphrase) {
println(" passphrase: " + c.passphrase)
}
if (c.properties.secret) {
println(" secret: " + c.secret)
}
if (c.properties.secretBytes) {
println(" secretBytes: ")
println("\n" + new String(c.secretBytes.getPlainData(), StandardCharsets.UTF_8))
println("")
}
if (c.properties.privateKeySource) {
println(" privateKey: " + c.getPrivateKey())
}
if (c.properties.apiToken) {
println(" apiToken: " + c.apiToken)
}
if (c.properties.token) {
println(" token: " + c.token)
}
println("")
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*s G 10
我知道这很老了,但是...使用管道非常简单。这是一个示例示例,它将凭证打印到控制台:
node {
def creds
stage('Sandbox') {
withCredentials([usernamePassword(credentialsId: 'my-creds', passwordVariable: 'C_PASS', usernameVariable: 'C_USER')]) {
creds = "\nUser: ${C_USER}\nPassword: ${C_PASS}\n"
}
println creds
}
}
Run Code Online (Sandbox Code Playgroud)
执行此管道会在控制台中产生以下内容:
Started by user First Last (username)
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /jenkins/workspace/sandbox
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Sandbox)
[Pipeline] withCredentials
[Pipeline] {
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] echo
User: testuser
Password: Ab37%ahc*z
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Run Code Online (Sandbox Code Playgroud)
这里的技巧是仅在withCredentials块内部屏蔽凭据。如果将它们分配给在块外定义的变量,然后在该块外打印该变量,则不会应用任何遮罩。据报道这是一个错误,但是对此没有做任何事情。
Leo*_*off 10
首先,您需要获取加密的值,该值方便地放置在value您感兴趣的凭据项的密码字段的属性中。导航到您在Jenkins UI中的凭据项,单击密码字段上的Inspect Element,然后复制value属性(类似{AQAABAAAa6VBbyzg5AWMW2RnfaBaj46}
然后,去JENKINS_URL/script执行println( hudson.util.Secret.decrypt("{AQAABAAAa6VBbyzg5AWMW2RnfaBaj46}") );解密的密码出现在输入字段下
如果您使用的是Jenkins凭证绑定插件,则可以将其写入密码到文件中。您不能只输出到控制台,因为插件会*****它。
| 归档时间: |
|
| 查看次数: |
37408 次 |
| 最近记录: |