Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #226: fix for bitbucket #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()