What is CI/CD?
CI/CD stands for Continuous Integration and Continuous Deployment (or Continuous Delivery). It is a set of practices and techniques used in software development to automate and streamline the process of building, testing, and deploying software applications.
Continuous Integration refers to the practice of frequently and automatically merging code changes from multiple developers into a shared version control repository. With CI, developers integrate their code changes as often as possible, usually multiple times a day. Each integration triggers an automated build and a series of tests to ensure that the code is functioning correctly and does not introduce any new bugs or conflicts with existing code.
Continuous Deployment (or Continuous Delivery) is an extension of Continuous Integration. It involves automating the deployment of software changes to production or staging environments after passing the necessary tests. In a continuous deployment setup, once the code changes are merged and pass all tests, they are automatically deployed to the target environment without manual intervention. This approach enables faster and more frequent releases of software, ensuring that the latest changes are quickly delivered to end users.
The key benefits of CI/CD include:
Rapid feedback: Developers receive quick feedback on their code changes, allowing them to identify and fix issues early in the development process.
Consistent integration: Frequent integration helps identify and resolve conflicts between code changes from different developers, leading to a more stable codebase.
Automated testing: Automated tests are an integral part of CI/CD pipelines, ensuring that code changes do not introduce regressions and maintaining the quality of the software.
Fast and reliable deployments: CI/CD pipelines automate the deployment process, reducing the chances of human error and enabling faster and more reliable releases.
Continuous improvement: CI/CD encourages an iterative and incremental approach to development, allowing teams to continuously improve their software through regular feedback and deployments.
What Is a Build Job?
A build job refers to a specific task or process within a CI/CD pipeline that is responsible for building the software application from source code. It is a fundamental step in the software development lifecycle and is typically automated as part of the continuous integration process.
In a build job, the source code of an application is retrieved from a version control system (such as Git), and various build tools and scripts are used to compile the code, resolve dependencies, and create an executable or deployable artifact. The specific steps involved in a build job can vary depending on the programming language, build tools, and project requirements.
Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.
Here are some common activities that may take place in a build job:
Compilation: The source code is compiled into machine-readable code or bytecode. This step ensures that the code is syntactically correct and can be executed by the target platform.
Dependency Management: The build job may involve resolving and downloading the necessary libraries, frameworks, or external dependencies required by the application. This ensures that the application has access to all the required components during runtime.
Testing: Automated tests can be executed as part of the build job to ensure that the code functions as expected and meets the defined quality standards. This may include unit tests, integration tests, or other types of tests depending on the project's testing strategy.
Code Quality Checks: Static code analysis tools can be employed to identify potential issues, such as code style violations, potential bugs, or security vulnerabilities. These checks help maintain code quality and adhere to coding standards.
Artifact Generation: Once the build process is complete, a deployable artifact (such as an executable file, a package, or a container image) is generated. This artifact represents the built version of the software that can be deployed to various environments.
Build jobs are typically configured and executed automatically whenever changes are pushed to the version control repository. The results of the build job, including any generated artifacts or test reports, are often made available for further stages in the CI/CD pipeline, such as deployment or additional testing.
By automating the build process within a build job, teams can ensure that the software is consistently built, tested, and ready for deployment, reducing the chances of manual errors and enabling faster and more reliable releases.
What are Freestyle Projects?
A freestyle project in Jenkins is a type of project that allows you to build, test, and deploy software using a variety of different options and configurations.
Freestyle Projects in Jenkins allow users to create highly customizable and flexible build and automation workflows. With Freestyle Projects, developers and teams have more control over the configuration and steps involved in their CI/CD pipelines compared to other project types in Jenkins, such as pipeline-based projects.
In a Freestyle Project, you have the freedom to define the sequence of build steps, specify build triggers, and configure build environments according to your project's specific requirements. Some of the key features and capabilities of Freestyle Projects in Jenkins include:
Build Steps: Freestyle Projects allow you to define a series of build steps, which can include executing shell commands, running scripts, invoking build tools, or performing other actions needed to build, test, and deploy your software.
Build Triggers: You can configure various build triggers to specify when a build should be triggered. This can be based on specific events, such as code commits, time-based schedules, or external triggers from other systems.
Build Environment: Freestyle Projects enable you to set up custom build environments by configuring parameters, environment variables, build agents, or selecting specific machines or nodes for the execution of your build steps.
Integration with Plugins: Jenkins offers a vast ecosystem of plugins that extend its functionality. Freestyle Projects allow you to leverage these plugins to integrate with external tools, generate reports, publish artifacts, or perform other actions to enhance your build process.
Post-Build Actions: After the build steps are executed, you can define post-build actions to be performed, such as archiving artifacts, sending notifications, triggering downstream builds, or publishing reports.
Freestyle Projects in Jenkins provide a flexible and intuitive way to configure and manage CI/CD pipelines, making it easier to adapt to different project requirements and workflows. However, it's worth noting that Jenkins also provides more advanced pipeline features with its declarative and scripted pipeline syntax, which offer more structured and version-controlled approaches to defining CI/CD pipelines.
Let's Create a Freestyle Project
Click on New Item.
Then write a Name for your project.
In the Description, write something to define the project.
Select GitHub Project and paste the Repository Link in the Project URL.
Select Git and Paste the Repository URL again.
In the Build section (Build Steps) you can write your steps:
echo "Hello I have started my DevOps Journey"
echo "I will build the code using docker"
docker build . -t react-django-app
echo "I will perform tests if required"
echo "I will deploy the code"
docker run -d -p 8001:8001 react-django-app:latest
Save it and Click on Build Now.
When it's done, Check the Console Output if it finished Success or not.
Now in Inbound Rules add 8001 so that we can access the application from the web.
Let's try to reach our application in a browser.Your_Public_IP:8001
It's up and running.
Good Job! You've successfully created your first Freestyle project on Jenkins.
Keep practising!!
I hope you learnt something from this Blog.
Happy Learning!