Introduction
In software development, continuous integration and continuous delivery (CI/CD) have become essential practices. Jenkins is one of the most popular and powerful automation servers.
So, to succeed in Jenkins and to ensure that we secure a Jenkins interview, we must give it our best shot. Here are some Jenkins Interview Questions to assist us in meeting and achieving our objectives.
This article is Part 3 of the Jenkins Interview Questions and Answer series covering the advanced-level Jenkins Interview questions.
Jenkins Interview Questions For Freshers
1. What is Continuous Testing?
Solution: Continuous Testing is a process where we execute automated testing as part of the software delivery pipeline. It is done to get feedback on the risks associated with software as soon as possible. It extends and evolves test automation to address the increased complexity of modern application development and delivery.
Continuous testing means that testing is done constantly without any disruption.
2. How is continuous integration achieved using Jenkins?
Solution: Continuous integration is when the code changes are constantly integrated into the main code and tested automatically. The results of the tests will decide if the change is ready for deployment. In this process -
- We make a change - commit/pull_request - in the dev branch.
- The Source Control Management (SCM) system generates appropriate events.
- Source Control Management specific Jenkins Plugins like SVN/Git will detect the events from the configured repositories. These events will be used for triggering build/test/dependent jobs on Jenkins.
- After the jobs are completed, the changes will be labelled as per the status of the test job.
- Based on the Status, the Continuous Deployment or Continuous Delivery strategy/tool will take it forward.
3. What is artifact archival & how to do it in Pipelines?
Solution:
Artifact is the storable/exportable/archivable results of a specific Jenkins job build. This can be configured with a plugin called Copy artifact Plugin. Based on the configured pattern, the directories/files matching the configured patterns will archive for a Jenkins build that can be used for future references.
In the pipeline, we can configure it as follows -
archiveArtifacts artifacts: 'output/**/*'
4. How to configure exclusions & inclusions in Artifacts Archival?
Solution: Artifact archival takes in a pattern to match target files. Similarly, it can take in a way for exclusion, which is ignored while selecting the files for archival.
E.g.
archiveArtifacts artifacts: 'output/*.docx', excludes: 'output/specific_file_name.docx'
The above line will archive all the text files from the output folder except specific_file.txt
5. How is code coverage tracked/measured using Jenkins in a CI environment?
Solution: We can track or measure the code coverage using language-specific code coverage plugins like CodeCov, JaCoCo, etc. or generic plugins/tools like Sonarqube, which can add the code coverage data to jobs with some minor changes in the code, and the same can be displayed/plotted as a graph in Jenkins.
6. What are the default environment Variables by Jenkins?
Solution: Jenkins provides various environment variables by default like - BRANCH_NAME, BUILD_TAG, BUILD_NUMBER, WORKSPACE, etc.
7. How can any job configuration be reset to the earlier version/state?
Solution: In the Job details page, we can use the Job Config History to see different reviews & can revert the Job configs from the history of a particular job. This is super useful when any job is misconfigured by someone mistakenly, and it can be reverted and reviewed easily to any earlier states.
8. How do we do global tools configuration in Jenkins?
Solution: We need to install global tools outside the Jenkins environment and control from the Jenkins environment. Hence it requires its corresponding Jenkins plugin as well. Following are the steps to using a global tool.
- Install the tool Plugin in the Jenkins instance to include the global tool in a list of global tools used by Jenkins.
- Install the tool in the Jenkins environment or make it available during runtime (maybe with a command to install and run it).
- Scroll through the tool list in Manage Jenkins -> Global Tools Configuration and configure the global tool-specific configurations.
- Use the global tool that has been deployed in your job/pipeline.
9. How to use & create a shared library in Jenkins?
Solution: The following are the minimum prerequisites for using a Jenkins shared library in pipeline code:
- In SCM, a repository containing pipeline common library code.
- For the Jenkins instance, a proper SCM Plugin configuration.
- Jenkins' global setup should include the Global Shared Library.
- Use the methods specified in the Jenkins Shared Library and include the Shared Library in the Pipeline Code.
For example,
#!/urs/bin/env groovy
@Library('fs_jenkins_shared_library@v2.0.7')_
10. How can we temporarily turn off Jenkins security if the admin has locked themselves out of the admin console?
Solution: A file called config.xml is located in the JENKINS HOME folder. This file contains an XML element entitled useSecurity that transforms to true when we enable security. If we set this value to false, security will be disabled the next time Jenkins runs.
<useSecurity>false</useSecurity>
However, we must remember that removing security should only be used as a last resort and only for a limited time. Re-enable Jenkins security and reboot the CI server after resolving the authentication issues.
Also read, Servicenow Interview Questions
11. How to download the Console log for a particular Jenkins build programmatically?
Solution: A file called config.xml is located in the JENKINS HOME folder. This file contains an XML element entitled useSecurity that transforms to true when we enable security. If we set this value to false, security will be disabled the next time Jenkins runs.
12. What is Jenkins Remote Access API?
Solution: Jenkins has a remote access API for most of its features (though some functionalities are programming language-dependent).
It is now available in three flavors: XML, JSON with JSONP support, and JSONP.
The Python Remote Access API follows the REST model. That is, instead of having a single entry point for all features, they are accessible via the ".../API/" URL, where the "..." section refers to the data that it processes.
For example, if our Jenkins installation is located at codingninjas.com, visiting /API/ will only provide the top-level API functionality — basically a list of the Jenkins instance's configured jobs.
13. What is in-process script approval, and how does it work?
Solution: Jenkins, and various plugins, allow us to execute Groovy scripts in Jenkins. To protect Jenkins from various malicious scripts, these plugins implement provided scripts in a Groovy Sandbox that limits what APIs are accessible.
The Script Security plugin provides this security. The "In-process Script Approval" action should display in "Manage Jenkins" as soon as an unsafe method is used in any of the scripts, allowing Administrators to decide which unsafe methods should be allowed in the Jenkins environment.
This in-process script approval enhances the security of the Jenkins ecosystem.
14. What do we mean by pipeline as a code?
Solution: Pipeline as Code refers to a set of features in Jenkins that allow users to define pipelined job processes using code stored and versioned in a source repository. Jenkins can now find, manage, and run jobs for various source repositories and branches, removing the need for manual job creation and maintenance.
Pipeline as code requires that projects have a Jenkinsfile file in the repository root that contains a "Pipeline script."
In addition, one of the enabling jobs in Jenkins must be configured:
- Multibranch Pipeline: automatically create many branches of a single repository
- Organization Folders: scan a GitHub Organization or Bitbucket Team to discover an organization's repositories and create managed Multibranch Pipeline jobs for them automatically.
15. Can we monitor Jenkins with common Observability tools?
Solution: Common monitoring platforms, such as JavaMelody, DataDog, Prometheus, and a few more, offer a Jenkins plugin that, once enabled, sends metrics to the relevant Monitoring platform, which can then be observed using the most up-to-date tools and technologies. Alarms and Notifications can be set up in the same way for immediate notification when something goes wrong.