Git integration with Jenkins the main objective here is how GitHub connects with Jenkins, once build tool maven works and then Java artifacts generated ready for deploy the application (.war file).
This post is 2 mins read.
Jenkins integration with GitHub Code repo build with maven |
Prerequisites:
You should have been Signup either on GitHub or Bitbucket
GitHub repo url: https://github.com/BhavaniShekhar/my-app
Global Tool configuration
- Java - defined name as LocalJDK8 or JDK8 /JDK11/JDK18
- Maven - defined name can be as LocalMaven or maven3
- Git - name defined as LocalGit or default
How to configure JDK as Global tool in Jenkins?
update-alternatives --display java
LocalJDK8 configuration |
How to Install and Configure Maven as tool in Jenkins?
java -version # to confirm Java installed yum install -y maven mvn --version # To confirm that Maven installed successfully
Configuring LocalMaven |
LocalGit configuration on Jenkins Global Tool Configuration |
How to Setup a Jenkins Maven Project?
Step 1: Configure new item with Freestyle project
Let's create Freestyle project with the following
Name: github-integration
In the General section enter
- Description: This is first java project will be build with maven.
- Discard old builds checked
- Max # of builds to keep: 1
Step 2: Source Code Management section select Git
- a. Repository URL value entry that uses Git clone https protocol.
- b. GitHub project will be mostly free and public repos, there is no need to create credentials. Go with 'none' option. If it's organization project it will be private repo you need to create credentials.
- Branch: You need to specify the branch name as master or main branch will be used as default. For testing purposes we have to change to feature or relative to the environment (dev,QA, prod etc).
Jenkins integration with GitHub - Source Control Management tab setup |
When you work on the real time project you may need to work on test/feature branch instead of master branch.
Step 3: Delete workspace before build
In the 'Build Environment' section, select the check box the 'Delete workspace before build starts'. There are more advanced options available but for now we can go with default.
Jenkins Build Environment - delete workspace before build starts |
Step 4: Build using Invoke top-level Maven targets
In the 'Build' section, add build step -> invoke top-level Maven targets.
- a. Maven version : LocalMaven
- b. Goals : test install or clean package
- c. POM : If it is available in the root directory nothing to mention if some other location then you need to specify the location example: maven-samples/single-module/pom.xml
- d. Now Save the project and all set to run it,
Jenkins Build - invoke top-level Maven targets |
/var/lib/jenkins/workspace/github-integration/target/myweb-0.0.1.war
No comments:
Post a Comment