50 Jenkins Commands & Concepts For MNC Interviews
50 Jenkins Commands & Concepts For MNC Interviews
1. What is Jenkins?
Key Points:
Jenkins Role:
● Command (Linux):
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key |
sudo apt-key add -
sudo apt update
sudo apt install jenkins
Explanation:
● Commands:
Explanation:
● Location:
/var/lib/jenkins
● Explanation: Jenkins home directory stores configuration files, plugins, and job
data.
● Command:
sudo tail -f /var/log/jenkins/jenkins.log
Explanation:
● Answer:
1. Enable Role-based Access Control.
2. Use an SSL certificate.
3. Configure credentials securely.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}
Explanation:
● Command:
pipeline {
environment {
ENV_VAR = 'value'
}
stages {
stage('Test') {
steps {
echo "Environment variable: ${ENV_VAR}"
}
}
}
}
Explanation:
● Answer:
○ Freestyle: Basic job setup with GUI.
○ Pipeline: Scripted or declarative workflows for complex automation.
H/15 * * * *
● Command:
Explanation:
● Answer: A text file that stores pipeline as code. Typically stored in a repository.
● Command:
cp -r /var/lib/jenkins /backup/location
Explanation:
● Command (CLI):
java -jar jenkins-cli.jar -s http://<JENKINS_URL>
install-plugin <PLUGIN_NAME>
● Answer:
○ Agent: A remote system that builds jobs.
○ Node: A machine where Jenkins runs jobs.
● Command:
● Command:
Explanation:
● Command:
pipeline {
agent {
docker { image 'node:14' }
}
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
}
}
● Command:
Example Command:
● Command:
● Answer:
○ Use the Build History and Dashboard.
○ Integrate monitoring tools like Prometheus.
● Command:
● Answer:
○ Stages represent the steps of the CI/CD process (e.g., Build, Test, Deploy).
● Command:
parameters {
string(name: 'BRANCH', defaultValue: 'main',
description: 'Branch to build')
}
● Command:
● Command:
post {
always {
mail to: '[email protected]', subject: 'Build
Complete', body: 'Details...'
}
}
● Command:
parallel {
stage('Test A') { steps { echo 'Running Test A' } }
● Command:
● Answer:
○ Check the Console Output.
○ Analyze logs in /var/log/jenkins.
● Answer: A trigger mechanism for CI when changes are pushed to the repository.
● Answer:
○ Use the Credentials plugin.
○ Mask secrets in pipelines.
● Command:
● Answer:
○ Scripted: More flexible, written in Groovy.
○ Declarative: Easier to use, structured syntax.
● Answer:
○ Use the AWS CLI and plugins like S3 Publisher.
● Command:
● Answer:
○ Add additional features like Git integration, Slack notifications, etc.
● Command: