🚀Day 29 : Jenkins Important interview Question😃

🚀Day 29 : Jenkins Important interview Question😃

¡

11 min read

Jenkins Interview

Here are some Jenkins-specific questions related to Docker that one can use during a DevOps Engineer interview:

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

Continuous integration

What you need (cost)

  • Your team will need to write automated tests for each new feature, improvement or bug fix.

  • You need a continuous integration server that can monitor the main repository and run the tests automatically for every new commits pushed.

  • Developers need to merge their changes as often as possible, at least once a day.

What you gain

  • Less bugs get shipped to production as regressions are captured early by the automated tests.

  • Building the release is easy as all integration issues have been solved early.

  • Less context switching as developers are alerted as soon as they break the build and can work on fixing it before they move to another task.

  • Testing costs are reduced drastically – your CI server can run hundreds of tests in the matter of seconds.

  • Your QA team spends less time testing and can focus on significant improvements to the quality culture.

Continuous delivery

What you need (cost)

  • You need a strong foundation in continuous integration and your test suite needs to cover enough of your codebase.

  • Deployments need to be automated. The trigger is still manual but once a deployment is started there shouldn't be a need for human intervention.

  • Your team will most likely need to embrace feature flags so that incomplete features do not affect customers in production.

What you gain

  • The complexity of deploying software has been taken away. Your team doesn't have to spend days preparing for a release anymore.

  • You can release more often, thus accelerating the feedback loop with your customers.

  • There is much less pressure on decisions for small changes, hence encouraging iterating faster.

Continuous deployment

What you need (cost)

  • Your testing culture needs to be at its best. The quality of your test suite will determine the quality of your releases.

  • Your documentation process will need to keep up with the pace of deployments.

  • Feature flags become an inherent part of the process of releasing significant changes to make sure you can coordinate with other departments (support, marketing, PR...).

What you gain

  • You can develop faster as there's no need to pause development for releases. Deployments pipelines are triggered automatically for every change.

  • Releases are less risky and easier to fix in case of problem as you deploy small batches of changes.

  • Customers see a continuous stream of improvements, and quality increases every day, instead of every month, quarter or year.

2. Benefits of CI/CD

Releasing software can be a painful and time-consuming process. One involving weeks of manual integration, configuration and testing while the ever-present risk of discovering a showstopper threatens to force everyone back to square one. The time commitment involved in getting code ready for release can mean changes are delivered every few months at best.

3. What is meant by CI-CD?

CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. The main concepts attributed to CI/CD are continuous integration, continuous delivery, and continuous deployment.

4. What is Jenkins Pipeline?

Jenkins Pipeline (or simply "Pipeline") is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins. A continuous delivery pipeline is an automated expression of your process for getting software from version control right through to your users and customers.

5. How do you configure the job in Jenkins?

Step 1 − Go to the Jenkins dashboard and Click on New Item

Step 2 − In the next screen, enter the Item name, in this case we have named it Helloworld. Choose the ‘Freestyle project option’

Step 3 − The following screen will come up in which you can specify the details of the job.

Step 4 − We need to specify the location of files which need to be built. In this example, we will assume that a local git repository(E:\Program) has been setup which contains a ‘HelloWorld.java’ file. Hence scroll down and click on the Git option and enter the URL of the local git repository.

Note − If you repository if hosted on Github, you can also enter the url of that repository here. In addition to this, you would need to click on the Add button for the credentials to add a user name and password to the github repository so that the code can be picked up from the remote repository.

Step 5 − Now go to the Build section and click on Add build step → Execute Windows batch command

Step 6 − In the command window, enter the following commands and then click on the Save button.

Javac HelloWorld.java
Java HelloWorld

Step 7 − Once saved, you can click on the Build Now option to see if you have successfully defined the job.

Step 8 − Once the build is scheduled, it will run. The following Build history section shows that a build is in progress.

Step 9 − Once the build is completed, a status of the build will show if the build was successful or not. In our case, the following build has been executed successfully. Click on the #1 in the Build history to bring up the details of the build.

Step 10 − Click on the Console Output link to see the details of the build

6. Where do you find errors in Jenkins?

In Jenkins, in the pipeline where failure occurred, in the pane, select the latest build, and click Console Output. On the Console Output page, check the logs to find the reason for the failure.

7. In Jenkins how can you find log files?

  1. From the Jenkins dashboard, click the job link name from the table.

  2. Click the build number in the Build History table in the sidebar.

  3. Click Console Output in the sidebar menu. The console output is displayed:

  4. If you need to send the console output to Perforce Support, send it as plain text.

8. Jenkins workflow and write a script for this workflow?

Jenkins Workflow is a plugin for Jenkins. Once installed, a new item type becomes available: a “Workflow”. Workflow projects can be used for the same purposes as regular “Freestyle” Jenkins projects, but they also have the ability to orchestrate much larger tasks that can span multiple projects, and even create and manage multiple workspaces in a single Workflow. What’s more, all of this management can be organized into a single script, rather than spread out across a collection of configurations, projects, and steps.

node {
3
  git 'https://github.com/redhotvengeance/hello-jenkins.git'
4
  sh 'uptime'
5
}

Let’s start scripting. First, we’ll open up a node block, just as before:

1
2
node {
3
4
}

Next, let’s clone our builder repo:

1
2
node {
3
  git 'https://github.com/redhotvengeance/jenkins-workflow-build.git'
4
}

Now we need to run our Gradle build script to generate the built.txt file:

1
2
node {
3
  git 'https://github.com/redhotvengeance/jenkins-workflow-build.git'
4
  sh 'gradle createBuild'
5
}

Finally, let’s make sure everything is working as we expect it to. We’ll add a cat to print out the contents of the built.txt file:

1
2
node {
3
  git 'https://github.com/redhotvengeance/jenkins-workflow-build.git'
4
  sh 'gradle createBuild'
5
  sh 'cat ./built.txt'
6
}

Click Save, and then start a build. Once it is done, take a look at the Console Output.

9. How to create continuous deployment in Jenkins?

Step 1 − Go to the Jenkins dashboard and click on New Item. Choose a ‘Freestyle project’ and enter the project name as ‘QA’. Click on the Ok button to create the project.

Step 2 − In this example, we are keeping it simple and just using this project to execute a test program for the Helloworld application.

So our project QA is now setup. You can do a build to see if it builds properly.

Step 3 − Now go to you Helloworld project and click on the Configure option

Step 4 − In the project configuration, choose the ‘Add post-build action’ and choose ‘Build other projects’

Step 5 − In the ‘Project to build’ section, enter QA as the project name to build. You can leave the option as default of ‘Trigger only if build is stable’. Click on the Save button.

Step 6 − Build the Helloworld project. Now if you see the Console output, you will also see that after the Helloworld project is successfully built, the build of the QA project will also happen.

Step 7 − Let now install the Delivery pipeline plugin. Go to Manage Jenkins → Manage Plugin’s. In the available tab, search for ‘Delivery Pipeline Plugin’. Click On Install without Restart. Once done, restart the Jenkins instance.

Step 8 − To see the Delivery pipeline in action, in the Jenkins Dashboard, click on the + symbol in the Tab next to the ‘All’ Tab.

Step 9 − Enter any name for the View name and choose the option ‘Delivery Pipeline View’.

Step 10 − In the next screen, you can leave the default options. One can change the following settings −

  • Ensure the option ‘Show static analysis results’ is checked.

  • Ensure the option ‘Show total build time’ is checked.

  • For the Initial job – Enter the Helloworld project as the first job which should build.

  • Enter any name for the Pipeline

  • Click the OK button.

You will now see a great view of the entire delivery pipeline and you will be able to see the status of each project in the entire pipeline.

Another famous plugin is the build pipeline plugin. Let’s take a look at this.

Step 1 − Go to Manage Jenkins → Manage Plugin’s. In the available tab, search for ‘Build Pipeline Plugin’. Click On Install without Restart. Once done, restart the Jenkins instance.

Step 2 − To see the Build pipeline in action, in the Jenkins Dashboard, click on the + symbol in the Tab next to the ‘All’ Tab.

Step 3 − Enter any name for the View name and choose the option ‘Build Pipeline View’.

Step 4 − Accept the default settings, just in the Selected Initial job, ensure to enter the name of the Helloworld project. Click on the Ok button.

You will now see a great view of the entire delivery pipeline and you will be able to see the status of each project in the entire pipeline.

10. How build job in Jenkins?

Step 1 − Go to the Jenkins dashboard and Click on New Item

Step 2 − In the next screen, enter the Item name, in this case we have named it Helloworld. Choose the ‘Freestyle project option’

Step 3 − The following screen will come up in which you can specify the details of the job.

Step 4 − We need to specify the location of files which need to be built. In this example, we will assume that a local git repository(E:\Program) has been setup which contains a ‘HelloWorld.java’ file. Hence scroll down and click on the Git option and enter the URL of the local git repository.

Note − If you repository if hosted on Github, you can also enter the url of that repository here. In addition to this, you would need to click on the Add button for the credentials to add a user name and password to the github repository so that the code can be picked up from the remote repository.

Step 5 − Now go to the Build section and click on Add build step → Execute Windows batch command

Step 6 − In the command window, enter the following commands and then click on the Save button.

echo "HelloWorld"

Step 7 − Once saved, you can click on the Build Now option to see if you have successfully defined the job.

Step 8 − Once the build is scheduled, it will run. The following Build history section shows that a build is in progress.

Step 9 − Once the build is completed, a status of the build will show if the build was successful or not. In our case, the following build has been executed successfully. Click on the #1 in the Build history to bring up the details of the build.

Step 10 − Click on the Console Output link to see the details of the build

11. Why we use pipeline in Jenkins?

Jenkins Pipeline is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins. A continuous delivery pipeline is an automated expression of your process for getting software from version control right through to your users and customers.

12. Is Only Jenkins enough for automation?

While Jenkins is a great Continuous Integration tool, it was simply not built for Continuous Delivery purposes. With this said, there are better tools than Jenkins that can help you automate and modernize CD processes and offer other benefits too

13. How will you handle secrets?

The easiest way to store secrets is to store them in a field of the type Secret, and access that field in your other code via a getter that returns the same type. Jenkins will transparently handle the encryption and decryption for on-disk storage.

14. Explain diff stages in CI-CD setup

The CI/CD pipeline combines continuous integration, delivery and deployment into four major phases: source, build, test and deploy. Each phase uses highly detailed processes, standards, tools and automation.

15. Name some of the plugins in Jenkin?

  • Git Plugin. Git is one of the most installed Jenkins add-ons available on its repository. ...

  • Kubernetes Plugin. Kubernetes is another widely used plugin in Jenkins. ...

  • Jira Plugin. ...

  • Docker Plugin. ...

  • Maven Integration Plugin. ...

  • Blue Ocean Plugin. ...

  • Amazon EC2 Plugin. ...

  • Pipeline Plugin.

Happy Learning :)

Â