Day 29: 90DaysOfChallenge

Day 29: 90DaysOfChallenge

Jenkins Interview Questions And Answers

  • What’s the difference between continuous integration, continuous delivery, and continuous deployment?

Continuous Integration is a part of Continuous Delivery and Continuous Deployment. The difference between continuous delivery and continuous deployment is the presence of a manual approval to update to production. Production happens automatically without explicit approval in continuous deployment where as Continuous delivery automates the entire software release process manually.

  • Benefits of CI/CD

Following are the benefits of CI/CD-

  • Faster Deployment

  • Faster Product Delivery

  • Easier rollback of code changes

  • Exclusive log generation

  • Reduced risk of defects

  • Higher efficiency of web development

  • What is meant by CI-CD?

CI or Continuous Integration is a DevOps Software Development practice where as soon as the code is ready and committed to the central code repository(Ex-GitHub or Bitbucket), it gets automatically build and tested.

CD or Continuous delivery is a software development practice where code changes are automatically prepared for a release to production.

  • What is Jenkins Pipeline?

Jenkins pipeline is a combination of plugins that support the integration and implementation of continuous delivery pipelines using Jenkins. It is a collection of jobs that brings the code from version control into the hands of the end users by using automation tools.

  • How do you configure the job in Jenkins?

Following are the steps to configure the job in Jenkins -

i)Login to Jenkins - Access the Jenkins dashboard.

ii)Create Job - Click on New Item from left side bar or Create a Job from the Dashboard Page.

iii)Provide Name - Enter the Item name.

iv)Select Job Type- Select Job type like Freestyle, Pipeline, etc and click OK.

v)Configure SCM - Select Git in Source Code Management section and provide the Repository url.

vi)Set build triggers - Select what should initiate the build like when code is pushed, scheduled build, etc.

vii)Configure Build Environment - Select the build environment if there's any related to configuration.

viii)Add Post-Build Actions: Define actions to take after the build completes (e.g., archive artifacts, send notifications).

vi)Save the Configuration.

  • Where do you find errors in Jenkins?

Errors in Jenkins can be found in -

Console Output - Select the latest build and click on Console Output. Check the logs to find the reason for the failure on Console Output.

System Log - Jenkins keeps a log of system events and errors which can be found at /var/log/jenkins/jenkins.log.

Build History - Failed builds are highlighted with red color in the Jenkins dashboard. Clicking on a failed build gives information about the error.

Notifications: Jenkins can send email notifications for failed builds if it is configured.

  • In Jenkins how can you find log files?

By default, Jenkins keeps a constant log of all activity as a part of the Jenkins dashboard. Go to Manage Jenkins and click the System Log button in the Status Information section. Click the All Jenkins Logs link to access the default log. The default location for Jenkins logs on Linux is /var/log/jenkins/jenkins.log. You can also view the log in the this path.

  • Jenkins workflow and write a script for this workflow?

Jenkins workflow mainly consists of 3 or 4 stages -

Code Clone - In this, the pipeline clones the repository from the specified url and branch.

Code Build - This builds the docker image from the dockerfile present in the code.

Code Test - This runs the test if there's any defined in the code.

Code Deploy - This finally deploys the built Docker image as a container.

pipeline {
    agent any

    stages {
        stage('Code') {
            steps {
                git url: "https://github.com/shilpi-22/node-todo-cicd.git", branch: "master"
                echo 'Code clone successful'
            }
        }
          stage('Build') {
            steps {
                sh 'docker build . -t node-todo-cicd'
                echo 'Code Build successful'
            }
        }
          stage("deploy") {
            steps {
                sh "docker-compose up -d" // Make sure docker-compose is installed and config is correct
                echo "Node-app deployment successful"
            }
        }
    }
}

The above script defines three stages: Code Clone, Build, and Deploy. The agent any directive specifies that the pipeline can execute on any available agent in the Jenkins environment. Each stage contains steps that execute specific commands. Code Clone step defines the git url and the branch from where code is to be cloned. Code Build builds the docker image "node-todo-cicd" using the dockerfile from the code. Code Deploy starts the container in detached mode using docker-compose up -d.

  • How to create continuous deployment in Jenkins?

    Creating continuous deployment in Jenkins involves setting up a pipeline that automatically builds, tests, and deploys your code whenever changes are pushed to your repository. To create continuous deployment in Jenkins, configure a Pipeline job to pull code from your GitHub repository and define stages for building, testing, and deploying. Enable the GitHub hook trigger for GitScm polling in the job settings and set up a webhook in your GitHub repository to notify Jenkins of code changes.

  • How build job in Jenkins?

    Following are the steps to configure the job in Jenkins -

    i) Login to Jenkins - Access the Jenkins dashboard.

    ii)Create Job - Click on New Item from left side bar or Create a Job from the Dashboard Page.

    iii)Provide Name - Enter the Item name.

    iv)Select Job Type- Select Job type like Freestyle, Pipeline, etc and click OK.

    v)Configure SCM - Select Git in Source Code Management section and provide the Repository url.

    vi)Set build triggers - Select what should initiate the build like when code is pushed, scheduled build, etc.

    vii)Configure Build Environment - Select the build environment if there's any related to configuration.

    viii)Add Post-Build Actions: Define actions to take after the build completes (e.g., archive artifacts, send notifications).

    vi)Save the Configuration.

  • Why we use pipeline in Jenkins?

The definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn can be committed to a project’s source control repository. This is the foundation of "Pipeline-as-code"; treating the CD pipeline as a part of the application to be versioned and reviewed like any other code.

  • Is Only Jenkins enough for automation?

No, Jenkins alone may not be sufficient for comprehensive automation. Additional tools and technologies might be needed depending on the specific requirements of your automation tasks, such as version control systems (e.g., Git), configuration management tools (e.g., Ansible, Puppet), containerization platforms (e.g., Docker, Kubernetes), and testing frameworks (e.g., Selenium).

  • How will you handle secrets?

    To handle secrets securely in Jenkins, you can use the built-in Credentials Plugin. This plugin allows to securely store sensitive information such as passwords, API tokens, and SSH keys. Here's how you can handle secrets in Jenkins:

    i) Use Credentials Plugin: Install and configure the Credentials Plugin in Jenkins.

    ii) Add Credentials: Go to "Manage Jenkins" > "Manage Credentials" and click on "Global credentials". Here, you can add credentials for various types such as Username with Password, SSH Username with Private Key, Secret Text, etc.

    iii) Reference Credentials in Jobs: In your Jenkins job configurations (such as Pipeline scripts), reference the credentials by their ID. Jenkins will securely inject the credentials at runtime.

  • Explain different stages in CI-CD setup.

The different stages in a CI/CD setup are:

i) Source: To fetch the latest code from version control (e.g., Git, Bitbucket).

ii) Build: Compile code and create deployable artifacts (e.g., executable files, Docker images).

iii) Test: Run automated tests(e.g., unit tests, integration tests, or acceptance tests) to ensure code quality and functionality.

iv) Deploy: Deploy the tested code to a target environment (e.g., staging, QA, UAT, production) using automation tools such as Ansible, Chef, or Puppet.

v) Release: This stage involves managing the release process, including creating release notes, versioning the software, and publishing the artifacts to a repository or package manager.

vi) Monitor: Set up monitoring to track the application's performance and health and diagnose any issues (e.g., performance issues, errors, or crashes) that may arise.

  • Name some of the plugins in Jenkin?

i) Jenkins pipeline - It orchestrate complex workflows in Jenkins using a domain-specific language (DSL).

ii) GitHub plugin - Integrates Jenkins with Git version control system for source code management.

iii) Selenium plugin - It allows Jenkins to integrate with Selenium which enables to automate browser testing of web applications.

iv) SonarQube plugin - Provides detailed reports on code quality, security, and maintainability.

v) Blue Ocean plugin - Offers an intuitive user interface for visualizing and managing CI/CD workflows.

Thanks for reading!

Hope it was helpful.