Search This Blog

Showing posts with label Jenkins. Show all posts
Showing posts with label Jenkins. Show all posts

Tuesday, March 26, 2019

Retrieving Jenkins Credentials passwords using Jenkins Script Console


https://github.com/tkrzeminski/jenkins-groovy-scripts/blob/master/show-all-credentials.groovy


import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey
import com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl
import org.jenkinsci.plugins.plaincredentials.StringCredentials
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl

def showRow = {
    credentialType, secretId, username = null, password = null, description = null - >
        println("${credentialType} : ".padLeft(20) + secretId ? .padRight(38) + " | " + username ? .padRight(20) + " | " + password ? .padRight(40) + " | " + description)
}

// set Credentials domain name (null means is it global)
domainName = null

credentialsStore = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0] ? .getStore()
domain = new Domain(domainName, null, Collections. < DomainSpecification > emptyList())

credentialsStore ? .getCredentials(domain).each {
    if (it instanceof UsernamePasswordCredentialsImpl)
        showRow("user/password", it.id, it.username, it.password ? .getPlainText(), it.description)
    else if (it instanceof BasicSSHUserPrivateKey)
        showRow("ssh priv key", it.id, it.passphrase ? .getPlainText(), it.privateKeySource ? .getPrivateKey(), it.description)
    else if (it instanceof AWSCredentialsImpl)
        showRow("aws", it.id, it.accessKey, it.secretKey ? .getPlainText(), it.description)
    else if (it instanceof StringCredentials)
        showRow("secret text", it.id, it.secret ? .getPlainText(), '', it.description)
    else if (it instanceof FileCredentialsImpl)
        showRow("secret file", it.id, it.content ? .text, '', it.description)
    else
        showRow("something else", it.id, '', '', '')
}

return

Thursday, February 1, 2018

Did you change your SVN ip and your Jenkins jobs are now failing? svn: E200015: No credential to try

Did you change your SVN ip and your Jenkins jobs are all failing now, even after your updated any ip references in the job configuration (stored at config.xml) to the new one ?

You may be missing this. This is was the missing bit that solved the problem for me.

In a short:

  1. Make sure you indeed changed all the old ip references in the config.xml to the new one (something I did before finding the article above, meaning this alone will not do it)
  2. Make sure you also update the ip in all credentials referencing the old ip.
  3. Restart jenkins
Your job should successfully complete now.