Skip to content

Commit

Permalink
issue #226: fix for bitbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsedova committed Apr 30, 2018
1 parent 9e7276e commit 3bdeca7
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions dockerizeit/master/bitbucket.groovy
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
import java.lang.System
import hudson.model.*
import jenkins.model.*
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.*

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


def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration")

// Note: Hook management only supported by Bitbucket Cloud (dec 2017, Bitbucket Branch Source Plugin 2.2.7).
// Note: Hook management only supported by Bitbucket Cloud (dec 2017, Bitbucket Branch Source Plugin 2.2.7).
// For bitbucket servers, ensure that manageHooks is disabled in properties to avoid confusion
// https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#bitbucket
properties.bitbucketEndpoints.each {
if(it.value.enabled) {
println "--> Create bitbucket server ${it.key}"
println it

AbstractBitbucketEndpoint endpoint
if(it.value.enabled) {
println "--> Create bitbucket server ${it.key}"

if (it.value.get('type', 'server') == 'cloud') {
endpoint = new BitbucketCloudEndpoint(it.value.get('manageHooks', false),
it.value.get('credentialsId', ""))
} else {
endpoint = new BitbucketServerEndpoint(it.value.get('name', ""),
it.value.get('serverUrl', ""),
it.value.get('manageHooks', false),
it.value.get('credentialsId', ""))
if (it.value.get('type', 'server') == 'cloud') {
try {
def cloudEndpointClazz = Class.forName("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint")
def cloudEndpointConstructor = cloudEndpointClazz.getDeclaredConstructor(boolean.class, String.class)
def cloudInstance = cloudEndpointConstructor.newInstance(it.value.get('manageHooks', false), it.value.get('credentialsId', ""))
desc.updateEndpoint(cloudInstance)
desc.save()
} catch (ClassNotFoundException ex) {
println "ERROR: Can not configure BitBucket no plugin installed"
return
}
} else {
try {
def serverEndpointClazz = Class.forName("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint")
def serverEndpointConstructor = serverEndpointClazz.getDeclaredConstructor(boolean.class, String.class)
def serverInstance = serverEndpointConstructor.newInstance(it.value.get('name', ""),
it.value.get('serverUrl', ""),
it.value.get('manageHooks', false),
it.value.get('credentialsId', ""))
desc.updateEndpoint(serverInstance)
desc.save()
} catch (ClassNotFoundException ex) {
println "ERROR: Can not configure BitBucket no plugin installed"
return
}
}
}

desc.updateEndpoint((AbstractBitbucketEndpoint)endpoint)
}
}

desc.save()

0 comments on commit 3bdeca7

Please sign in to comment.