#Day23 : Jenkins Freestyle Project for DevOps Engineers.

#Day23 : Jenkins Freestyle Project for DevOps Engineers.

ยท

4 min read

What is CI/CD?

  • CI or Continuous Integration is the practice of automating the integration of code changes from multiple developers into a single codebase. It is a software development practice where the developers commit their work frequently into the central code repository (Github or Stash). Then there are automated tools that build the newly committed code and do a code review, etc as required upon integration. The key goals of Continuous Integration are to find and address bugs quicker, make the process of integrating code across a team of developers easier, improve software quality and reduce the time it takes to release new feature updates.

  • CD or Continuous Delivery is carried out after Continuous Integration to make sure that we can release new changes to our customers quickly in an error-free way. This includes running integration and regression tests in the staging area (similar to the production environment) so that the final release is not broken in production. It ensures to automate the release process so that we have a release-ready product at all times and we can deploy our application at any point in time.

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 agent for your app. ( which you deployed from docker in earlier task)

For creating an agent, go to build executor status and create node

Give name to node and select permanent agent.

Give description for the node of for what it is going to be used.

Give root directory as ubuntu/home.

In usage select use as much as possible and select web socket and click on save.

  • Create a new Jenkins freestyle project for your app.

Now configure the freestyle project created in the previous blog.

Go to build steps and configure the steps in the pipeline.

Give permissions in node agent server to the file that needs to be accessed through pipeline.

Use chmod 777 node-todo-app

Now in build steps, enter the commands in the steps -

cd /home/ubuntu/projects/node-todo-cicd

This will take us in the directory where the app files are stored.

  • In the "Build" section of the project, add a build step to run the "docker build" command to build the image for the container.

    Now lets build an image for running the container for the application -

    docker build . -t todo-dev

  • Add a second step to run the "docker run" command to start a container using the image created in step 3.

    Now lets run a container from the built image -

docker run -d -p 8000:8000 todo-dev

It will look like this -

Click on save

Now go the app dashboard>first jenkins project,

and click on Build Now.

Your freestyle project is now ready!

You can check Console output to see what is happening in the background.

Task-02

  • Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file (Hint- use day-19 Application & Database docker-compose file)

Create another freestyle projects by following the above steps until add build steps.

We have already learnt how to create a Docker compose file on day 19. The app will already contain the docker-compose file that we built. Now in build steps(execute shell), type the following -

cd /home/ubuntu/projects/django-todo-cicd

docker-compose up -d

Now go to Dashboard>django-todo-cicd and click on build now.

You can check Console output to see what is happening in the background.

  • 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.

If we make the build twice, that is if the container is already running the build may fail. Hence we need to stop the previous running container before doing docker compose-up.

Add this before docker-compose up -d

docker compose down

Now 'build now' again.

Console output will show the commands running in background.

ย