Build Spring Boot-Maven Project with Jenkins and copy the artifact in to local directory.
Here we are going to discuss the way of generation .jar or .war file out of spring boot project with Jenkins from remote repository and copy the final artifact either in .jar or .war extension file into another location by Jenkins.
Pre-requisites
- Jenkins should be installed in server : http://{ip}:{port}
- Remote git repository with spring boot source code.
1. Jenkins Login Page
2. Configure Jenkins
- Configure JDK.
- Configure Maven.
- Bit-bucket plugin management.
2.1 Configure JDK
After login to the jenkins go to,
ManageJenkins -> GlobalToolConfiguration -> JDK
- Unchecked the Install automatically field.
- Enter any name in Name text box as you wish like Jenkin-Java
- Enter the JAVA_HOME path of your server location here. In my case JDK has been installed at /usr/lib/jvm/java-8-openjdk-amd64
2.2 Configure Maven
After login to the jenkins go to,
ManageJenkins -> GlobalToolConfiguration -> Maven
- Unchecked the Install automatically field.
- Enter any name in Name text box as you wish like Jenkin-Maven
- Enter the MAVEN_HOME path of your server location here. In my case Maven has been installed at /usr/lib/mvn
2.3 Bit-bucket Plugin Management
After login to the jenkins go to,
ManageJenkins -> ManagePlugins -> Available
- Then type “bitbucket” in search box.
- You will be seen Bitbucket plugin once you scroll down little bit.
- Select the plugin and click on Install without restart button.
You will be redirected to following UI and then checked the check box once you see the success message as shown in the screen shot.
3. Create New Item/Job
Now we are going to configure our existing spring boot project available in bitbucket repository so that project build automatically.
3.1 Create New Item
After login to the jenkins go to New Item
- Enter item name.
- Select Maven Project.
- Then OK.
3.2 Configure New Item
After login to the jenkins
- You will be seen Adaptor-Service in the dashboard.
- Select Configure.
3.3 New Item-General
You can configure general details of the job under the General tab as shown in the image. Note that selecting Discard old builds option is optional
3.4 New Item-Source Code Management
This is the place where you can manage your source code to generate the final build.
- Select the Git option
- Then you have to configure git repository url and credential in order to get the source code by jenkins.
3.5 New Item Bitbucket Credentials
Enter your bitbucket username in username text box and password in Password text box.
3.5 Bitbucket URL and Credentials
Final stage of the source code management tab should be as follows. Note that you can configure the branch that jenkins going to engage with under the Branch Specifier field. The default one is /master branch but it is better to keep separate branch dedicated for releases. In our case that branch would be /TestRelease
3.6 New Item-Build
No need to configure Build Trigger, Build Environments and PreSteps at first place. So leave them with default values.
In the Build tab you can set the Goals and Options of your final build generated by jenkins using bitbucket resource.
Some available options for Goals and Options as follows.
- clean package -> clean the project and package as .jar or .war based on the pom.xml file in the project.
- clean package -Dmaven.test.skip=true -> Same output will be generated but skip the test cases.
3.7 New Item-Post Step
You can use this place to configure some additional thins to the final output after completion of the build.
As a example I want to move final artifact from /workspace to another directory(location) because by auto deployment process is pointing to that place.
In order to achieve this, you can use custom shellscript or bat to give those instruction as follows.
4. Build Newly Created Item
Now all the necessary configurations are done. Then navigate to main dashboard after apply and save all the changes in new item configuration.
Select the configured job and click on Build Now.
5. Final output
You can see final output file in configured location (refer 3.7). In our case final output is a .jar file and is available in following location.
Have a Nice Day !!!!!