jenkins + gitlab auto build and deploy to tomcat

Step 1: Download jenkins.war file from  here.

Step 2: On server create user jenkins

Step 3: Add user jenkins as sudoer execute the command to access the 

 file:

Step 4: Add jenkins follow below

Switch to user jenkins test command sudo

Step 5:  download tomcat 7 from here or using wget to download

 

Step 6: Edit bin/catalina.sh of tomcat to set JENKINS_HOME

Step 7: Deploy jenkins.war download from step 1 to tomcat webapps

Step 8: Change owner to user jenkins

Step 9: (Optional) Run tomcat port 80 as non root user

Step 10: Go to browser access url : http://your-ip/jenkins and  setup jenkins user/pass.

Step 11:  After jenkins setup done, click  Manage Jenkins – Manage Plugins and Install gitlab plugin.

Step 12: (Optional) If you install offline, download all .hpi below:

  1. junit.hpi
  2. jsch.hpi
  3. xunit.hpi
  4. workflow-step-api.hpi
  5. workflow-scm-step.hpi
  6. structs.hpi
  7. apache-httpcomponents-client-4-api.hpi
  8. credentials.hpi
  9. display-url-api.hpi
  10. ssh-credentials.hpi
  11. script-security.hpi
  12. scm-api.hpi
  13. matrix-project.hpi
  14. mailer.hpi
  15. javadoc.hpi
  16. maven-plugin.hpi
  17. git-client.hpi
  18. git.hpi
  19. gitlab-plugin.hpi

At tab Manage Plugins – Advanced – Upload Plugin and upload follow order of downloaded hpi

Step 13: After finish install plugin go to Manage Jenkins – Configure System – scroll to Gitlab

Config follow image below

Step 14:  On browser of git lab -> Setting -> Account -> get Private token

Step 15:  On browser of jenkins -> Click button Add -> paste token from gitlab follow here

after that, click button test connection.

Step 16:  On home page of jenkins, click button New Item, enter your item name and  choose Free Style Project.

Step 17: Config item

At tab General – GitLab connection – choose gitlab

Execute command below to set non verify ssl

At tab Source Code Management – Config follow image 

At tab Build Triggers – Config follow image

Note: Copy url at GitLab CI Service URL to next step

At tab Build – Config follow image

$WORKSPACE is variables of jenkins

Step 18: Create shell script build-rms.sh and upload it in /app/tools/jenkins/tomcat/bin/

Step 19: Chmod executable for script

DONE setup jenkins auto build war file and deploy to tomcat.

Now, We will setup Webhook on gitlab. When user pushed to repository, gitlab will trigger jenkins build source (using url at Step 17)

1.In gitlab – open Settings -> Integrations .

2.Enter your url from Step 17 in input URL.

3. Choose Push Events

4. Disable checkbox Enable SSL verification

5. Click button Add Webhook

DONE setup webhook for gitlab

TROUBLE SHOOTING:

Error: When you run jenkins job and get error :  sudo: sorry, you must have a tty to run sudo

Solution: FIX follow here

Leave a Reply

Your email address will not be published. Required fields are marked *