Jenkins For Building SpringBoot#
Jenkins Configurations#
- Now, firstly when the Jenkins is started, you should goes to
Manage Jenkins
-->Manage Nodes And Clouds
as the image below:
- Then you can see, by default
Jenkins
will have an built-in node which is your real machine that you are using to runJenkins
bydocker
. - Then you need to go
Manage Jenkins
->Global Tool Configuration
as the image below
- Then you scroll down to find the tag
Maven
. You should put aName
then chooseInstall automatically
and then choose theVersion
of Maven that you want to install.
- Next you scroll to tag
JDK
and put a name for it likeJDK8
. We don't need to install JDK 8 anymore because we already have JDK 8 by default inside the docker imagejenkins
.
- Finally, you scroll to tag
Git
and put aName
-> setPath to Git executable
as/usr/bin/git
-> chooseInstall automatically
. Click buttonSave
.
Create Pipeline On Jenkins#
- Now, we will try to create a pipeline on Jenkins for building SpringBoot project. Firstly, you go to
Dashboard
and clickNew Item
. - Then you set a
Name
-> chooseMultibranch Pipeline
-> clickOk
.
- Next, in tag
Branch Sources
, you put some information about yourGitHub Repository
andBranch
that you want Jenkins clones and builds. - Note: you can set multi
branches
for Jenkins Build.
- Next, You scroll down and config
Build Configuration
andScan Multibranch Pipeline Triggers
as the image below. - Note that
Script Path
is thepath
toJenkinsfile
in your GitHub repository(your source code on GitHub). - For
Scan Multibranch Pipeline Triggers
choosePeriodically if not otherwise run
andInterval
as1 minute
.Interval
means when your repository has changed so the pipeline will be triggered automatically after 1 minute. - Finally click
Save
Create Jenkins File In Your Repository#
- So let craete a folder in the root of your repository name
jenkins
and a file namebuild.Jenkinsfile
as you defined in theJenkins Pipeline
.
- In the file
build.Jenkinsfile
. Let’s add scripts as below
build.Jenkinsfile | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
- Now, let’s commit and push your code changes to your respository and check the Jenkins Pipeline, You can see It’s built successfully.
- So, That’s it. Thanks and Good luck!