The last continuous integration tool that we are going to configure is Atlassian Bamboo. Bamboo is a commercial continuous integration server. There is a 30-day evaluation license available from the Atlassian website. We will discuss how to configure Bamboo to use Gradle as a build tool for our Java project.
We can install Bamboo on our local computer. We will first need to download the installation package from the Bamboo website. We can choose native installers for Mac OS X, Windows, and Linux. Alternatively, we can simply download a packaged version and unzip it in a directory on our computer. Finally, we can download a WAR file and deploy it to a web container.
Defining a plan
Bamboo has no Gradle runner or plugin, but we can define a build plan and add the so-called script task. A script task can run any script as part of the build plan. To make sure that Bamboo can build our Java project, we must add the Gradle Wrapper scripts to the project.
We will run the wrapper task in our local Java project directory. We now have the gradlew and gradlew.bat script files. Also, the gradle directory is created with the configuration for the Gradle Wrapper. We add the directory and files to our Git repository, as follows:
We are now ready to create a new build plan in Bamboo:
We will start a web browser and open http://localhost:8085/. After we have logged in to Bamboo, we will select the Create Plan link. We will go to a new page, where we can set the properties of the build plan:
Creating a new plan in Bamboo
We must define a project name in the Project name field. Bamboo also expects a short identifier in uppercase characters as the project key in the Project Key field. The plan that is part of the project also has a name and key; we fill the Plan name and Plan key fields. We can set a short description in the Plan description field.
In the Source Repositories section, we can define the Git repository location for our project.
Finally, in the Build Strategy section, we will set the value of the Build Strategy drop-down box to Manual. This means that we have to manually start the build via the run action in the Bamboo user interface.
We will click on the Configure Tasks button to add tasks to our plan. A task contains some logic that we want to execute as part of the plan:
Adding a new task to the plan
The first task is automatically added and it is responsible to check the source code of the Git repository. We will click on the Add task button to create a new task:
Searching for script task
A dialog window will appear, where we will select the Script task from the Builder section. With this task, we can configure the Gradle Wrapper scripts to be executed.
We will return to the tasks window and we fill in the fields under the Script configuration:
Configuring the script task
We fill a description in the Task description field. Script location must be set to File instead of Inline. The Script file field has the location of the gradlew or gradlew.bat script that we want invoked.
In the Argument field, we will pass the arguments to the gradlew script. We want to invoke the build task, so we set the value to build.
We are ready to click on the Save button to save our script task configuration. The task is added to the list of tasks, as shown in the following screenshot:
Configuration for the script task to run Gradle
We can enable the plan in the Enable this Plan? section by checking the Yes please! checkbox. Next, we will click on the Create button to finish the configuration and save the plan in Bamboo.
Overview of plan
Running the build plan
We are now ready to run the build:
Click on the Run button at the top-right side of the page. While the build is running, we can see some of the log output. After the build is finished, we can see the results.
We also want to add the project artifacts to our plan, and the test results as well. Therefore, we will select the Configure plan option from the Actions menu:
Build results after running the plan
We will then go to the Artifacts tab page and click on the Create definition button to add a new artifact definition:
Defining artifacts for the plan
We will see a dialog window and we can define Name, Location, and Copy Pattern of the artifacts here:
Configuration for artifacts
We fill artifacts in the Name field and build/libs in the Location field. The Copy pattern field is filled with the *.jar value to include all JAR files. We then click on the Create button to finish the configuration of the artifacts.
Next, we will select the Tasks tab page and click on the Add task button to create a new task.
Searching for task to publish test results
In the dialog window with Tasks types, we will select JUnit Parser from the Tests section. Bamboo shows the configuration fields for this task:
Configuration for test results task
We will then set Task description with the Test results value. In the Specify custom results directories field, we will set the build/test-results/*.xml pattern.
We are now ready to run our plan again; but this time, we have the test results:
Summary of build results
We will click on the Artifacts tab and see that the plan has produced artifacts:
Overview of artifacts for the plan
If we click on the artifacts link, we are taken to a page where we can download each artifact JAR file, as shown in the following screenshot: