-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexsedova
committed
Apr 30, 2018
1 parent
9e7276e
commit 3bdeca7
Showing
1 changed file
with
30 additions
and
20 deletions.
There are no files selected for viewing
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
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() |