All about CI/CD

All about CI/CD

- Introduction

  • CI means Continues Integration and CD means Continues Delivery/Deploy.
  • Whenever developers write code, we integrate all that code of all developers at that point of time and we build, test and deliver/deploy to the client. This process we call CI & CD.
  • Jenkins is a tool helps in achieving this. So instead of doing night builds, build as and when commit occurs by integrating all code in SCM tool, build, test and checking the quality of that code is what we call Continues Integration.
  • Integrate: Combine all code written by developers till some point of time.
  • Build: Compile the code and make a small executable package.
  • Test: Test in all environments whether application is working properly or not.
  • Archived: Stored in an artifact so that in future we may use/deliver again.
  • Deliver: Handing the product to Client
  • Deploy: Installing product in client’s machines.

- Continues Integration

  1. Manually: – Manually write code, then do build manually and then test manually by writing test cases and deploy manually into clients machine.
  2. Scripts: – Can do above process by writing scripts so that these scripts do CI&CD automatically. But here complexity is, writing script is not so easy.
  3. Tool: – Using tools like Jenkins is very handy. Everything is pre-configured in these type of tools. So less manual intervention. This is the most preferred way.

- Benefits of CI

  1. Detects bugs as soon as possible, so that bug will be rectified fast and development happens fast.
  2. Complete automation, No need manual intervention.
  3. We can intervene manually whenever we want. I.e. we can stop any stage at any point of time so have better control.
  4. Can establish complete and continues work flow.

- Jenkins

  • An open source automation server which enables developers around the world to reliably build, test, and deploy their software.

- Jenkins Workflow

  • Attach Git, Maven, Selenium & Artifactory plug-ins to Jenkins.
  • Once Developers put the code in Git, Jenkins pulls that code and send to Maven for build.
  • Once build is done, Jenkins pulls that built code and send to selenium for testing.
  • Once testing is done, then Jenkins will pull that code and send to Artifactory as per requirement and finally we can deliver the end product to client we call Continues delivery.
  • We can also deploy with Jenkins into clients machine directly as per the requirement. This is what Jenkins work flow.

- Jenkins Architecture

  • Jenkins architecture is Client-Server model.
  • Where ever, we install Jenkins, we call that server is Jenkins master.
  • We can create slaves also in Jenkins, so that, server load will be distributed to slaves.
  • Jenkins master randomly assigns tasks to slaves. But if you want to restrict any job to run in particular slave, then we can do it so that, that particular job will be executed in that slave only. We can group some slaves by using “Label”

- Types of configurations in Jenkins

  1. Global: – Here, whatever configuration changes we do, applicable to whole Jenkins including jobs as well as nodes. This configuration has high priority.
  2. Job: – These configurations applicable to only Jobs. Jobs also we call as projects or items in Jenkins.
  3. Node: – These configurations applicable to only nodes. Also we call Slaves. These are kind of helpers to Jenkins master to distribute the excessive load.

- Jenkins workspace

  • The workspace is the location on your computer where Jenkins places all files related to the Jenkins project. By default each project or job is assigned a workspace location and it contains Jenkins-specific project metadata, temporary files like logs and any build artifacts, including transient build files.
  • Jenkins web page acts like a window through which we are actually doing work in workspace.

- Free style project in Jenkins

  • ? Create project by giving any name ? Select Free style project ? Click on build ? Select execute windows batch command ? Give any command (echo “Hello World!!”) ? Select Save ? Click on Build now ? Finally can see Console output

- Plugins in Jenkins

  • ? With Jenkins, nearly everything is a plugin and that nearly all functionality is provided by plugins. You can think of Jenkins as little more than an executor of plugins. ? Plugins are small libraries that add new abilities to Jenkins and can provide integration points to other tools. ? Since nearly everything Jenkins does is because of a plugin, Jenkins ships with a small set of default plugins, some of which can be upgraded independently of Jenkins

- Maven Project

  • ? Select new item ? Copy the git hub maven project link and paste in git section in Jenkins ? Select build ? Click on clean package ? Select save ? Click on Build now ? Verify workspace contents with GitHub sideSee console output

- Schedule projects

To schedule a job, ? Click on any project ? Click on Configure ? Select on Build triggers ? Click on Build periodically ? Give timing (* * * * *) ? Select Save ? Can see automatic builds every 1 min ? You can manually trigger build as well if you want

- Upstream and Downstream projects

  • These are the ways through which, we connect jobs one with other.
  • In Upstream jobs, first job will trigger second job after build is over.
  • In Downstream jobs, second job will wait till first job finishes its build. As and when first job finishes its work, then second job will be triggered automatically.
  • In Upstream, first job will be active. In Downstream jobs, second job will be active. We can use any one type to link multiple jobs.

- User Administration in Jenkins

  • In Jenkins, we can create users, groups and can assign limited privileges to them so that, we can have better control on Jenkins.
  • Users will not install Jenkins in their machines. They access Jenkins as a user. Here we can’t assign permissions directly to users.
  • Instead we create “Roles” and assign permissions to those roles. These roles we attach to users so that users get the permissions whatever we assign to those roles.

- Maven

  • Maven is one of the Build tools. It is the most advance build tool in the market. In this, everything is already pre-configured.
  • Maven belongs to Apache Company. We use maven to build Java code only.
  • We can’t build other codes by using Maven. By default, we get so many plugins with Maven. You can write your own plug-in as well.
  • Maven’s local repository is “.M2” where we can get required compilers and dependencies. Maven’s main configuration file is “pom.xml” where we keep all instructions to build.

- Advantages of Maven

  1. Automated tasks (Mention all in pom.xml)
  2. Multiple Tasks at a time
  3. Quality product
  4. Minimize bad builds
  5. Keep history & Save time – Save money
  6. Gives set of standards
  7. Gives define project life cycle (Goals)
  8. Manage all dependencies
  9. Uniformity in all projects
  10. Re-usability

- Architecture of Maven

  • Main configuration file is pom.xml. For one project, there will be one workspace and one pom.xml
  • Requirements for build: – ? Source code (Will be pulled from Git hub) ? Compiler (Pulls from remote repo and then put them in local repo, from there, maven pulls into Workspace) ? Dependencies (Pulls from remote repo and then put them in local repo, from there, maven pulls into Workspace)

- Maven’s Build Life Cycle

  • In maven, we have different goals. These are ? Generate resources (Dependencies) ? Compile code ? Unit test ? Package (Build) ? Install (in to local repo & artifactory) ? Deploy (to servers) ? Clean (delete all run time files)

Multi-Module Project in Maven

? Dividing big project into small modules, we call Multi Module Project. ? Each module must have its own SRC folder & pom.xml so that build will happen separately ? To build all modules with one command, there should be a parent pom.xml file. This calls all child pom.xml files automatically ? In parent pom.xml file, need to mention the child pom.xml files in an order.

119. What

要查看或添加评论,请登录

社区洞察

其他会员也浏览了