Best practices for setting up a preconfigured dockerized Jenkins

299 views
Skip to first unread message

Kirill

unread,
Oct 19, 2016, 12:21:56 PM10/19/16
to Jenkins Developers
Hi noble Jenkins developers,

I am trying to fully automate my Jenkins-based job execution environment and facing some issues there. I still have to do some steps manually :(
My base image is 1.651.3.

1. I need to have a job preconfigured. Tried different ways, the best one seems to be creating one programmatically from XML via Jenkins API, in Groovy script placed in init.groovy.d. However, even if job was created (no errors given, and object hash is available in debug), sometimes Jenkins needs to be reloaded in order for it to appear :(
2. I have slaves populated via Swarm plugin. The problem is that slaves do not connect until I go to the global Jenkins config and press "Save" - otherwise slaves complain about Jenkins not having the URL configuration available yet. I cannot think of a way to make it fully automated. How is it possible to define this URL before Jenkins start?
3. I have a hashed password for RabbitMQ connection set in my config.xml. When this XML is used to create a job, RabbitMQ rejects the attempts to connect with the password provided saying it's "plaintext". However, connection validation in a job UI config form works fine. All that is needed is to open the config and save it. Looking at the config.xml I see that the password hash has changed. How to get around this without the manual config saving? Programmatic .save() doesn't help :(

Regards,
Kirill.

Petr Archakov

unread,
Oct 20, 2016, 4:28:03 AM10/20/16
to Jenkins Developers
Hi Kirill,

I am now sure, if all of these will work in your particular use case, but I was able to achieve all three points mentioned programatically with Groovy script in init.groovy.d. Although I'm using Jenkins 2.x, I expect it also should work with older versions.

1. I use Job DSL plugin for this. Just place following script to init.groovy.d:

import javaposse.jobdsl.dsl.DslScriptLoader
import javaposse.jobdsl.plugin.JenkinsJobManagement
def workspace = new File('.')
def jobManagement = new JenkinsJobManagement(System.out, [:], workspace)
new DslScriptLoader(jobManagement).runScript("job('test')")

2. One option would be to try Jenkins.instance.reload(). I achieve this by running following script in init.groovy.d:

def locationConfig = Jenkins.instance.getDescriptor('JenkinsLocationConfiguration')
locationConfig.setUrl("<YOUR_LOCATION>")

3. Again, Jenkins.instance.reload() might help. Jenkins actually uses master key (which is different for every setup) to encode passwords. If you configure RabbitMQ programatically, you can put a proper hash right away with:

new hudson.util.Secret("<PLAIN_TEXT_PASSWORD>")

Hope it helps.

Cheers,
Petr

Kirill

unread,
Oct 25, 2016, 10:41:43 AM10/25/16
to Jenkins Developers
Hi Petr,

You're a legend :-) Your advices worked, comrade. Thanks a million!!

I didn't use Job DSL, Jenkins.instance.reload() appeared to be all I needed to make changes effective (project and global address).
I put "z_" prefix for the reload script to make sure it's run in the last turn - that's how it's defined in docs, and that's how it really worked.

Regarding RabbitMQ - it appeared that if you set a PLAIN password in config.xml that you use to create the job instance, it works like a charm.

Thanks again!!

Regards,
Kirill.


четверг, 20 октября 2016 г., 9:28:03 UTC+1 пользователь Petr Archakov написал:
Reply all
Reply to author
Forward
0 new messages