Day 23 Task: Jenkins Freestyle Project for DevOps Engineers.
What is CI/CD?
What Is a Build Job?
A Jenkins build job contains the configuration for automating a specific task or step in the application building process. These tasks include gathering dependencies, compiling, archiving, or transforming code, and testing and deploying code in different environments.
Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.
What is 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. Here are a few tasks that you could complete when working with a freestyle project in Jenkins.
Task-01
Create a new Jenkins freestyle project for your app.
3. Select "Freestyle project" and give the project a name.
4. Click on the "OK" button to create the project.
In the project configuration page, you can specify the details of the project, such as the source code management system, build triggers, and build actions. In GitHub project write your GitHub project repository URL.
In the "Source Code Management" section, you can specify the repository location, such as Git and Select branch name "main"
In the "Build" section of the project, add a build step to run the "docker build" command to build the image for the container.
Add a second step to run the "docker run" command to start a container using the image created in step 3.
Recommended by LinkedIn
Click on the "Save" button to save the project configuration.
Build the project: You can manually build the project by clicking on the "Build Now" link in the project's main page. This will start the build process and execute the steps specified in the project configuration.
After a build is completed, you can view the console output by clicking on the "Console Output" link in the build page. This will show the output of the commands that were executed during the build
You can see image and container is created. also project from GitHub deploy to ubuntu EC2 instance at location /var/lib/jenkins/workspace/jenkins-project-name.
Task-02
Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file
Set up a cleanup step in the Jenkins project to run "docker-compose down" command to stop and remove the containers defined in the compose file.
1.Create docker-compose.yml file inside your project
2. In the "Build" section of the project, add a build step "docker-compose down" command to stop and remove the containers defined in the compose file. then add "docker-compose up -d" command.
3. Build the project.
4. After a build is completed, you can view the console output.
5. You can see container is created.
browse your-ip:8001
Happy Learning.