Jenkins Interview questions and answers
We have reached to end of the Jenkins session. Here are some Jenkins-specific questions and answers that one can use during a DevOps Engineer interview:
1. What’s the difference between continuous integration, continuous delivery, and continuous deployment? What you need (cost)
Continuous Integration (CI):
What it is: Frequent code integration into a shared repository, ensuring multiple daily merges.
What You Need (Cost): Establishing automated tests, a CI server for automated testing on every commit, and emphasis on frequent code merging. Initial setup may require investment in testing suites and CI server configuration.
Continuous Delivery (CD):
What it is: Expands CI by automating the release process for consistent deployability at any time.
What You Need (Cost): Built on CI, it requires a solid CI foundation, automated deployments, potential use of feature flags, and a focus on consistent deployability. Additional tooling and process adjustments may be necessary.
Continuous Deployment (CD):
What it is: Further automation, deploying code changes to production after passing all tests.
What You Need (Cost): Demands a robust CI/CD pipeline, a strong testing culture, thorough documentation to match deployment pace, and incorporation of feature flags for inter-departmental coordination. Achieving CD requires significant investments in testing, automation, and coordination.
Overall, each stage requires investments in infrastructure, tools, testing frameworks, and potentially team training to adapt to automation and frequent code changes. While there are initial setup costs, continuous processes streamline development, testing, and deployment, leading to superior software quality and faster release cycles.
2. Benefits of CI/CD
Releasing software often involves prolonged manual integration, configuration, and testing, taking weeks. There's a constant risk of encountering critical issues that could reset progress. This extensive preparation for code release typically results in infrequent updates, sometimes spanning months between deliveries.
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 that 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 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 your 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 username 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?
From the Jenkins dashboard, click the job link name from the table.
Click the build number in the Build History table in the sidebar.
Click Console Output in the sidebar menu. The console output is displayed:
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.
Let’s start scripting. First, we’ll open up a node block, just as before:
Next, clone our builder repo:
Now we need to run our Gradle build script to generate the built.txt file:
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:
Click Save, and then start a build. Once it is done, take a look at the Console Output.
9. How to create a 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 demo 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 demo as the project name to build. You can leave the option as the default of ‘Trigger only if the 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 demo 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 demo-pipeline. 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 that need to be built. In this example, we will assume that a local git repository 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?
The Jenkins Pipeline consists of plugins that aid in creating and integrating continuous delivery pipelines within Jenkins. These pipelines automate the process of delivering software, starting from version control all the way to end users and customers, embodying your software delivery process in an automated manner.
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.