@@ -12,7 +12,7 @@ import java.util.concurrent.ExecutorService
1212import java.util.concurrent.Executors
1313import java.util.concurrent.Future
1414
15- class JsmAndBitbucketH2Deployment implements Deployment {
15+ class JsmAndBitbucketH2Deployment implements Deployment {
1616
1717 String friendlyName = " JIRA and Bitbucket H2 Deployment"
1818 String containerNetworkName = " jsm_and_bitbucket"
@@ -39,11 +39,9 @@ class JsmAndBitbucketH2Deployment implements Deployment{
3939 this . subDeployments = [new JsmH2Deployment (jiraBaseUrl), new BitbucketH2Deployment (bitbucketBaseUrl)]
4040
4141
42-
43-
4442 }
4543
46- ArrayList<Container > getContainers() {
44+ ArrayList<Container > getContainers () {
4745 return [jsmContainer, bitbucketContainer]
4846 }
4947
@@ -52,15 +50,15 @@ class JsmAndBitbucketH2Deployment implements Deployment{
5250 }
5351
5452 JsmH2Deployment getJsmH2Deployment () {
55- return subDeployments. find{ it instanceof JsmH2Deployment } as JsmH2Deployment
53+ return subDeployments. find { it instanceof JsmH2Deployment } as JsmH2Deployment
5654 }
5755
5856 JsmContainer getJsmContainer () {
5957 return jsmH2Deployment. jsmContainer
6058 }
6159
6260 BitbucketH2Deployment getBitbucketH2Deployment () {
63- return subDeployments. find{ it instanceof BitbucketH2Deployment } as BitbucketH2Deployment
61+ return subDeployments. find { it instanceof BitbucketH2Deployment } as BitbucketH2Deployment
6462 }
6563
6664 BitbucketContainer getBitbucketContainer () {
@@ -98,7 +96,6 @@ class JsmAndBitbucketH2Deployment implements Deployment{
9896 */
9997
10098
101-
10299 private class SetupDeploymentTask implements Callable<Boolean > {
103100
104101 Deployment deployment
@@ -117,8 +114,8 @@ class JsmAndBitbucketH2Deployment implements Deployment{
117114
118115 log. info(" Setting up deployment:" + friendlyName)
119116
120- assert jiraLicense : " Error no Jira License has been setup"
121- assert bitbucketLicense : " Error no Bitbucket License has been setup"
117+ assert jiraLicense: " Error no Jira License has been setup"
118+ assert bitbucketLicense: " Error no Bitbucket License has been setup"
122119
123120 jsmH2Deployment. setJiraLicense(new File (jiraLicense))
124121 bitbucketH2Deployment. setBitbucketLicence(new File (bitbucketLicense))
@@ -132,33 +129,68 @@ class JsmAndBitbucketH2Deployment implements Deployment{
132129 threadPool. shutdown()
133130
134131
135- while (! jsmFuture. done || ! bitbucketFuture. done) {
132+ while (! jsmFuture. done || ! bitbucketFuture. done) {
136133 log. info(" Waiting for deployments to finish" )
137134 log. info(" \t JSM Finished:" + jsmFuture. done)
138135 log. info(" \t Bitbucket Finished:" + bitbucketFuture. done)
139136
140- if (bitbucketFuture. done) {
137+ if (bitbucketFuture. done) {
141138 log. info(" \t Bitbucket deployment finished successfully:" + bitbucketFuture. get())
142139 }
143140
144- if (jsmFuture. done) {
141+ if (jsmFuture. done) {
145142 log. info(" \t JSM deployment finished successfully:" + jsmFuture. get())
146143 }
147144
148145 sleep(5000 )
149146 }
150- if (bitbucketFuture. done) {
147+ if (bitbucketFuture. done) {
151148 log. info(" \t Bitbucket deployment finished successfully:" + bitbucketFuture. get())
152149 }
153150
154- if (jsmFuture. done) {
151+ if (jsmFuture. done) {
155152 log. info(" \t JSM deployment finished successfully:" + jsmFuture. get())
156153 }
157154
158- if (jiraAppsToInstall) {
159- installJiraApps()
155+ if (jiraAppsToInstall) {
156+ log. info(" \t Installing user defined JIRA Apps" )
157+ assert installJiraApps(): " Error installing user defined JIRA apps"
158+ log. info(" \t\t Finished installing user defined JIRA Apps" )
159+ }
160+
161+ if (! jiraAppsToInstall. any { it. key. contains(" JiraShortcuts" ) }) {
162+ log. info(" \t Installing JiraShortcuts app" ) // Needed for setting up applink to bitbucket
163+ assert installJiraApps(
164+ [
165+ " https://github.com/eficode/JiraShortcuts/raw/packages/repository/com/eficode/atlassian/JiraShortcuts/2.0-SNAPSHOT-groovy-3.0/JiraShortcuts-2.0-SNAPSHOT-groovy-3.0.jar" : " "
166+ ]
167+ ) : " Error installing JiraShortcuts JIRA apps"
168+ log. info(" \t\t Finished installing JiraShortcuts JIRA Apps" )
160169 }
161170
171+ if (jiraRest. scriptRunnerIsInstalled()) {
172+ log. info(" \t Setting up application link between JIRA and Bitbucket" )
173+
174+
175+ String appLinkScript = getClass(). getResourceAsStream(" /instanceScripts/jira/SetupApplicationLink.groovy" ). text
176+ appLinkScript = appLinkScript. replaceFirst(" BITBUCKET_URL" , bitbucketBaseUrl)
177+ appLinkScript = appLinkScript. replaceFirst(" BITBUCKET_USER" , " admin" )
178+ appLinkScript = appLinkScript. replaceFirst(" BITBUCKET_PASSWORD" , " admin" )
179+
180+ log. trace(" \t\t Using Script:" )
181+ appLinkScript. eachLine {line ->
182+ log. trace(" \t " * 3 + line)
183+ }
184+
185+ Map appLinkResult = jiraRest. executeLocalScriptFile(appLinkScript)
186+ log. debug(" \t\t Finished executing application link script" )
187+ log. trace(" \t " * 3 + " Script returned logs:" )
188+ appLinkResult. log. each {log. trace(" \t " * 4 + it)}
189+
190+ assert appLinkResult. log. any {it. contains(" Created Bitbucket Application Link" )} : " Error creating application link from JIRA to bitbucket"
191+ assert appLinkResult. success : " Error creating application link from JIRA to bitbucket"
192+ log. info(" \t Finished setting up application between JIRA and Bitbucket successfully" )
193+ }
162194
163195
164196 return jsmFuture. get() && bitbucketFuture. get()
@@ -168,7 +200,7 @@ class JsmAndBitbucketH2Deployment implements Deployment{
168200 @Override
169201 void setupSecureDockerConnection (String host , String certPath ) {
170202
171- subDeployments. each {deployment ->
203+ subDeployments. each { deployment ->
172204 deployment. setupSecureDockerConnection(host, certPath)
173205 }
174206 }
@@ -178,12 +210,12 @@ class JsmAndBitbucketH2Deployment implements Deployment{
178210 * @param appsAndLicenses key = App url (from marketplace), value = license string (optional)
179211 * @return true if no apps where installed, or apps where installed successfully
180212 */
181- boolean installJiraApps (Map<String ,String > appsAndLicenses = jiraAppsToInstall ) {
213+ boolean installJiraApps (Map<String , String > appsAndLicenses = jiraAppsToInstall) {
182214
183215 if (appsAndLicenses) {
184216 log. info(" Installing ${ appsAndLicenses.size()} jiraapp(s)" )
185- appsAndLicenses. each {url , license ->
186- assert jiraRest. installApp(url, license) : " Error installing app:" + url
217+ appsAndLicenses. each { url , license ->
218+ assert jiraRest. installApp(url, license): " Error installing app:" + url
187219 }
188220 }
189221
@@ -192,5 +224,4 @@ class JsmAndBitbucketH2Deployment implements Deployment{
192224 }
193225
194226
195-
196227}
0 commit comments