Вы находитесь на странице: 1из 11

CI-CD Demo with Jenkins

1. Create a New Job in Jenkins, Select Job type FreeStyle

2. Enable Log rotation to keep no. of builds minimized on Jenkins Server


CI-CD Demo with Jenkins
3. Make build Parametrized , if more than one branch is in picture for build, Set Branch names as
choice parameter, Variable name is “Branch”

4. Enable Git SCM to fetch source code from Github repository, I have taken java code which can
be built with Maven build tool and output artifact is war
5. Select credentials if github repo is protected/private
6. In Branch section mention the Parameter variable “Branch”
CI-CD Demo with Jenkins

7. If required enable Poll SCM or Scheduled build for automated builds

8. In Build Section , select Maven option


9. Select maven tool name as set in Global tool configuration, I have set it as “M3”
10. Type Maven goal, for this project it is Package
11. It will default Buildfile i.e. pom.xml from workspace

12. If you want to deploy this WAR to a target server, the we have to install one plugin called
“Publish Over SSH”, this plugin allow us to send build artifacts to a remove server with ssh and
we can also execute commands on remote server
13. After installing plugin got to Global setting of Jenkins and Add a New SSH Server
14. Fill required values, Name, Hostname, user , Password or SSH key
15. I have used username and password
CI-CD Demo with Jenkins
16. Test Connection, it should return Success

17. Now come back to Jenkins Job, got to Post build Section
18. Select send build artifacts over SSH
19. Select Target Server
20. Select Source files, as our Source files is generated in Workspace/target folder
21. And war name is CounterWebApp.war
22. Now mention an intermediate folder on remote server, I have mentioned war , this folder will
be created in /root / of the target machine
23. Now mention commands to deploy war file
24. First I am removing old war and folder from webapps directory of tomcat
25. Now copy latest war from “war ” directory to webapps folder
26. If necessary tomcat restart can be issued
CI-CD Demo with Jenkins

27. As post build action , if build fails an email can be sent to stake holders, to use this SMTP
configuration should be valid in jenkins global configuration

28. Save the project, go to home page of project


29. Click on Build with parameter option on left hand side list
CI-CD Demo with Jenkins

30. Select a branch to Build, I have selected master


31. Click on Build

32. Build will start


33. Click on build number to see build details
CI-CD Demo with Jenkins

34. Some build details can be seen on this page

35. Click on console output to see each step by step verbose log
CI-CD Demo with Jenkins

36. Console output will look like this

37. Build was successful, war was created using maven and deployed to target server
CI-CD Demo with Jenkins

38. WAR file can be verified from the workspace aslo


CI-CD Demo with Jenkins
39. On target Server, inside webapps folder of Tomcat, new war can be seen, with new folder with
same as WAR name

40. Hit tomcat server IP(I have nginx as proxy to access tomcat on port 80) with WAR name as
context, i.e. CounterWebApp, Application will load

41. Pass a value in URL after context and it will show on the web page and counter will increase
CI-CD Demo with Jenkins

This whole project can aslo be created as Jenkins Pipeline JOB, with Groovy Script

Вам также может понравиться