Skip to content

Commit

Permalink
Fix #143: add more classes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsedova committed Mar 24, 2017
1 parent eefc489 commit 0c4f131
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
15 changes: 4 additions & 11 deletions dockerizeit/master/credentials.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ import java.lang.System
import jenkins.*
import hudson.model.*
import jenkins.model.*
// Plugins for SSH credentials
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*

// Read properties
def home_dir = System.getenv("JENKINS_HOME")
def properties = new ConfigSlurper().parse(new File("$home_dir/jenkins.properties").toURI().toURL())

global_domain = Domain.global()
global_domain = com.cloudbees.plugins.credentials.domains.Domain.global()
credentials_store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()

properties.credentials.each {
Expand All @@ -24,17 +17,17 @@ properties.credentials.each {
switch (it.value.type) {
case "ssh":
println "--> Create ssh credentials for user ${it.value.userId} with SSH private key ${it.value.path}"
creds = new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL,
creds = new com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey(com.cloudbees.plugins.credentials.CredentialsScope.GLOBAL,
it.value.credentialsId,
it.value.userId,
new BasicSSHUserPrivateKey.FileOnMasterPrivateKeySource(it.value.path),
new com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.FileOnMasterPrivateKeySource(it.value.path),
it.value.passphrase,
it.value.description)
credentials_store.addCredentials(global_domain, creds)
break
case "password":
println "--> Create credentials for user ${it.value.userId} with the password from ${it.value.path}"
creds = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
creds = new com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl(com.cloudbees.plugins.credentials.CredentialsScope.GLOBAL,
it.value.credentialsId,
it.value.description,
it.value.userId,
Expand Down
6 changes: 2 additions & 4 deletions dockerizeit/master/initialjobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import hudson.model.*
import jenkins.model.*
import javaposse.jobdsl.plugin.*
import hudson.triggers.TimerTrigger
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition

def instance = Jenkins.getInstance()
def home_dir = System.getenv("JENKINS_HOME")
Expand All @@ -17,8 +15,8 @@ properties.seedjobs.each {
def job = Jenkins.instance.getJob(it.value.name)
if (job) { job.delete() }
println "--> Create ${it.value.name} seed jod"
def project = Jenkins.instance.createProject(WorkflowJob.class, it.value.name)
project.setDefinition(new CpsFlowDefinition("""
def project = Jenkins.instance.createProject(org.jenkinsci.plugins.workflow.job.WorkflowJob.class, it.value.name)
project.setDefinition(new org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition("""
import javaposse.jobdsl.plugin.*
node("${properties.global.variables.utility_slave}") {
Expand Down
7 changes: 3 additions & 4 deletions dockerizeit/master/securityAD.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import java.lang.System
import jenkins.model.*
import hudson.plugins.active_directory.*
import com.google.common.collect.Lists

def home_dir = System.getenv("JENKINS_HOME")
Expand All @@ -9,15 +8,15 @@ def properties = new ConfigSlurper().parse(new File("$home_dir/security.properti
if(properties.ad.enabled) {
println "--> Configure AD"
def realm = new hudson.plugins.active_directory.ActiveDirectorySecurityRealm(properties.ad.domain,
Lists.newArrayList(new ActiveDirectoryDomain(properties.ad.domain, properties.ad.server)),
Lists.newArrayList(new hudson.plugins.active_directory.ActiveDirectoryDomain(properties.ad.domain, properties.ad.server)),
properties.ad.site,
properties.ad.bindName,
properties.ad.bindPassword,
properties.ad.server,
GroupLookupStrategy.valueOf(properties.ad.groupLookupStrategy.toString().toUpperCase()),
hudson.plugins.active_directory.GroupLookupStrategy.valueOf(properties.ad.groupLookupStrategy.toString().toUpperCase()),
true,
true,
new CacheConfiguration(1000, 6000))
new hudson.plugins.active_directory.CacheConfiguration(1000, 6000))
Jenkins.instance.setSecurityRealm(realm)
Jenkins.instance.save()
}
3 changes: 1 addition & 2 deletions dockerizeit/master/slaves.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import java.lang.System
import hudson.model.*
import jenkins.model.*
import hudson.slaves.*
import hudson.plugins.sshslaves.*
import hudson.model.Node.*

// load helpers and read properties
Expand All @@ -21,7 +20,7 @@ properties.slaves.each {
launcher = new JNLPLauncher()
break
case "ssh":
launcher = new SSHLauncher(it.value.host, // The host to connect to
launcher = new hudson.plugins.sshslaves.SSHLauncher(it.value.host, // The host to connect to
it.value.get('port', 22), // The port to connect on
it.value.credentialsId, // The credentials id to connect as
it.value.get('jvmOptions',""), // Options passed to the java vm
Expand Down

0 comments on commit 0c4f131

Please sign in to comment.