database-mysql and Secret

62 views
Skip to first unread message

Peter Miklosko

unread,
Mar 22, 2013, 12:39:33 PM3/22/13
to jenkin...@googlegroups.com
I'm playing with database-mysql and trying to get connection through it. However I can't get plain string password encrypted to Secret.
However Secret.formString() gives me NPE. Am I missing something?

public static Connection getConnection(String host, String dbName, String username, String password, String properties) {
        Secret secret = Secret.fromString(password);
        MySQLDatabase  database = new MySQLDatabase(host, dbName, username, secret, properties);
        Connection conn = null;
        try {
            conn = database.getDataSource().getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

java.lang.NullPointerException
at jenkins.security.ConfidentialStore.get(ConfidentialStore.java:66)
at jenkins.security.ConfidentialKey.load(ConfidentialKey.java:47)
at jenkins.security.CryptoConfidentialKey.getKey(CryptoConfidentialKey.java:32)
at jenkins.security.CryptoConfidentialKey.decrypt(CryptoConfidentialKey.java:67)
at hudson.util.Secret.decrypt(Secret.java:137)
at hudson.util.Secret.fromString(Secret.java:186)
at com.novoda.persistence.PersistenceManager.getConnection(PersistenceManager.java:25)
at com.novoda.persistence.PersistenceManagerTest.test_should_create_connection_and_close_without_error(PersistenceManagerTest.java:74)

Vojtech Juranek

unread,
Mar 24, 2013, 8:35:47 PM3/24/13
to jenkin...@googlegroups.com
Hi,

> java.lang.NullPointerException
> at jenkins.security.ConfidentialStore.get(ConfidentialStore.java:66)

how do you run it, do you run it within Jenkins? It seems
Jenkins.getInstance() returns null

HTH
Vojta

Peter Miklosko

unread,
Mar 25, 2013, 2:16:48 AM3/25/13
to jenkin...@googlegroups.com
Hey Vojta,

yes this is part of Jenkins plugin we trying to put together to save some stats in DB.It is run on post build so surely there shouldn't be null

Cheers

Peter


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/OfF95ueGABA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Peter Miklosko

unread,
Mar 25, 2013, 7:45:08 AM3/25/13
to jenkin...@googlegroups.com
My sincere apology,  I should not really code when I'm ill and not thinking straight. NPE was part of the JUnit test which is not running against Jenkins instance, hence Jenkins NULL. 

Back to paracetamol and more sleep.

Cheers 

Peter

Jesse Glick

unread,
Mar 26, 2013, 2:13:15 PM3/26/13
to jenkin...@googlegroups.com
On 03/25/2013 07:45 AM, Peter Miklosko wrote:
> NPE was part of the JUnit test which is not running against Jenkins instance

Try:

@Rule public JenkinsRule j = new JenkinsRule();
Reply all
Reply to author
Forward
0 new messages