Skip to content

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:

 #zoom

 #zoom

  • Then you can see, by default Jenkins will have an built-in node which is your real machine that you are using to run Jenkins by docker.
  • Then you need to go Manage Jenkins -> Global Tool Configuration as the image below

 #zoom

  • Then you scroll down to find the tag Maven. You should put a Name then choose Install automatically and then choose the Version of Maven that you want to install.

 #zoom

  • Next you scroll to tag JDK and put a name for it like JDK8. We don't need to install JDK 8 anymore because we already have JDK 8 by default inside the docker image jenkins.

 #zoom

  • Finally, you scroll to tag Git and put a Name -> set Path to Git executable as /usr/bin/git -> choose Install automatically. Click button Save.

 #zoom

Create Pipeline On Jenkins#

  • Now, we will try to create a pipeline on Jenkins for building SpringBoot project. Firstly, you go to Dashboard and click New Item.
  • Then you set a Name -> choose Multibranch Pipeline -> click Ok.

 #zoom

  • Next, in tag Branch Sources, you put some information about your GitHub Repository and Branch that you want Jenkins clones and builds.
  • Note: you can set multi branches for Jenkins Build.

 #zoom

  • Next, You scroll down and config Build Configuration and Scan Multibranch Pipeline Triggers as the image below.
  • Note that Script Path is the path to Jenkinsfile in your GitHub repository(your source code on GitHub).
  • For Scan Multibranch Pipeline Triggers choose Periodically if not otherwise run and Interval as 1 minuteInterval means when your repository has changed so the pipeline will be triggered automatically after 1 minute.
  • Finally click Save

 #zoom

Create Jenkins File In Your Repository#

  • So let craete a folder in the root of your repository name jenkins and a file name build.Jenkinsfile as you defined in the Jenkins Pipeline.

 #zoom

  • 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
pipeline {
    agent any
    tools {
        maven 'Maven 3.8.6'
        jdk 'JDK8'
    }
    stages {
        stage('Build') {
            steps {
                sh 'printenv'
                sh 'ls -la'
                sh 'mvn clean install -DskipTests'
            }
        }
        stage("Run Test") {
            steps {
              sh 'mvn test'
            }
        }
    }
}
  • Now, let’s commit and push your code changes to your respository and check the Jenkins Pipeline, You can see It’s built successfully.

 #zoom

 #zoom

  • So, That’s it. Thanks and Good luck!

See Also#