Created
April 18, 2016 19:20
-
-
Save jhoblitt/ce91b458526e3a03d365e2689db825f0 to your computer and use it in GitHub Desktop.
configuring the kubernetes jenkins plugin via groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.csanchez.jenkins.plugins.kubernetes.* | |
import jenkins.model.* | |
def j = Jenkins.getInstance() | |
def k = new KubernetesCloud( | |
'jenkins-test', | |
null, | |
'https://130.211.146.130', | |
'default', | |
'https://citest.lsst.codes/', | |
'10', 0, 0, 5 | |
) | |
k.setSkipTlsVerify(true) | |
k.setCredentialsId('ec5cf56b-71e9-4886-9f03-42934a399148') | |
def p = new PodTemplate('centos:6', null) | |
p.setName('centos6') | |
p.setLabel('centos6-docker') | |
p.setRemoteFs('/home/jenkins') | |
k.addTemplate(p) | |
p = new PodTemplate('lsstsqre/centos:7-docker', null) | |
p.setName('centos7') | |
p.setLabel('centos7-docker') | |
p.setRemoteFs('/home/jenkins') | |
k.addTemplate(p) | |
j.clouds.replace(k) | |
j.save() |
While I haven't tried it, I assume it should be a case of finding the KubernetesCloud
object and calling #addTemplate
on it.
Maybe something like this should help!
def kcloud
if (Jenkins.instance.clouds) {
kcloud = Jenkins.instance.clouds.get(0)
println "cloud found: ${Jenkins.instance.clouds}"
} else {
kcloud = new KubernetesCloud(conf.kubernetes.name)
Jenkins.instance.clouds.add(kcloud)
println "cloud added: ${Jenkins.instance.clouds}"
}
This is great, thanks for the public post!
I would love to now see how this script can be called at launch time (eg. the leader comes up, how do I now attach and launch this script to the leader), but I realize that's a totally different scope of work and investment than your quick work here.
Thanks again!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
This is a handy script. Do you know of a way to script adding templates to an existing kubernetes config in jenkins? Your script adds a new kube cloud and pod templates. I just need to add pod templates to an existing kube cloud.