What is the main purpose of build tools like Maven, Gradle, and npm?
Build tools automate the process of compiling code, managing dependencies, running tests, and packaging applications so developers can focus on writing code.
Click to reveal answer
beginner
How does Maven manage project dependencies?
Maven uses a file called pom.xml where you list your project dependencies. It downloads these dependencies from central repositories automatically.
Click to reveal answer
intermediate
What is the key difference between Maven and Gradle?
Maven uses XML files for configuration, which are more rigid, while Gradle uses a flexible Groovy or Kotlin DSL allowing more customization and faster builds.
Click to reveal answer
beginner
What file does npm use to manage dependencies and scripts?
npm uses package.json to list dependencies and define scripts to automate tasks like testing and building.
Click to reveal answer
intermediate
How can Jenkins integrate with build tools like Maven, Gradle, and npm?
Jenkins can run build tool commands in its pipelines or freestyle jobs to automate building, testing, and deploying projects continuously.
Click to reveal answer
Which file does Maven use to define project dependencies?
Asettings.xml
Bpom.xml
Cpackage.json
Dbuild.gradle
✗ Incorrect
Maven uses pom.xml to manage project dependencies and build configuration.
What language is used to write Gradle build scripts?
AGroovy or Kotlin
BXML
CJSON
DYAML
✗ Incorrect
Gradle build scripts are written in Groovy or Kotlin DSL, which allows flexible configuration.
Which command installs dependencies listed in npm's package.json?
Anpm build
Bnpm update
Cnpm run
Dnpm install
✗ Incorrect
The command 'npm install' downloads and installs all dependencies listed in package.json.
In Jenkins, how do you typically run a Maven build?
ABy running 'npm start'
BBy editing package.json
CBy running 'mvn clean install' in a build step
DBy writing XML in Jenkinsfile
✗ Incorrect
Jenkins runs Maven builds by executing commands like 'mvn clean install' in build steps or pipelines.
Which build tool is primarily used for JavaScript projects?
Anpm
BGradle
CMaven
DAnt
✗ Incorrect
npm is the standard package manager and build tool for JavaScript projects.
Explain how Maven, Gradle, and npm help automate software builds.
Think about the steps you do manually when preparing software to run.
You got /5 concepts.
Describe how Jenkins can use build tools to create a continuous integration pipeline.
Consider how Jenkins automates the developer's workflow.
You got /5 concepts.
Practice
(1/5)
1. What is the primary purpose of build tools like Maven, Gradle, and npm in Jenkins pipelines?
easy
A. To automate compiling, testing, and packaging code
B. To write application code manually
C. To deploy applications to production servers
D. To monitor server health and uptime
Solution
Step 1: Understand build tools' role
Build tools automate tasks like compiling code, running tests, and packaging software.
Step 2: Connect with Jenkins pipeline usage
Jenkins pipelines use these tools to automate software delivery steps efficiently.
Final Answer:
To automate compiling, testing, and packaging code -> Option A
Quick Check:
Build tools automate build tasks = D [OK]
Hint: Build tools automate code build and test steps [OK]
Common Mistakes:
Confusing build tools with deployment tools
Thinking build tools write code
Mixing monitoring tools with build tools
2. Which of the following is the correct Jenkins pipeline syntax to run a Maven build command?
easy
A. sh 'gradle build'
B. bat 'npm install'
C. bat 'mvn deploy'
D. sh 'mvn clean install'
Solution
Step 1: Identify the shell command for Maven
Maven commands run in shell using sh 'mvn ...' in Jenkins on Linux agents.
Step 2: Match the correct Maven build command
mvn clean install compiles and packages the project.
Final Answer:
sh 'mvn clean install' -> Option D
Quick Check:
Maven build command in shell = C [OK]
Hint: Use sh 'mvn clean install' for Maven builds on Linux [OK]
Common Mistakes:
Using npm or gradle commands for Maven builds
Using bat instead of sh on Linux agents
Confusing deploy with build commands
3. Given this Jenkins pipeline snippet, what will be the output if the npm install command fails?
pipeline {
agent any
stages {
stage('Install') {
steps {
sh 'npm install'
}
}
}
}
medium
A. Pipeline continues to next stage ignoring failure
By default, if sh command fails, Jenkins stops the pipeline and marks build as failed.
Step 2: Apply this to npm install failure
If npm install fails, the pipeline will stop immediately and fail.
Final Answer:
Pipeline stops and marks build as failed -> Option B
Quick Check:
Failed shell command stops pipeline = A [OK]
Hint: Failed shell commands stop Jenkins pipeline by default [OK]
Common Mistakes:
Assuming pipeline continues after failure
Thinking Jenkins retries commands automatically
Confusing unstable with failed build status
4. You wrote this Jenkins pipeline step to run Gradle build but it fails with 'command not found':
sh 'gradle build'
What is the most likely cause and fix?
medium
A. Gradle is not installed or not in PATH; install Gradle or set PATH
B. Syntax error in Jenkinsfile; change to bat 'gradle build'
C. Use npm instead of Gradle for Java projects
D. Replace 'build' with 'install' in the command
Solution
Step 1: Analyze error 'command not found'
This error means the system cannot find the gradle command in the PATH.
Step 2: Fix by installing Gradle or updating PATH
Ensure Gradle is installed on the Jenkins agent and its bin directory is in the PATH environment variable.
Final Answer:
Gradle is not installed or not in PATH; install Gradle or set PATH -> Option A
Quick Check:
Command not found means missing install or PATH = A [OK]
Hint: Check PATH and install Gradle if 'command not found' error occurs [OK]
Common Mistakes:
Using Windows bat syntax on Linux agents
Confusing npm with Gradle for Java builds
Changing command without fixing environment
5. You want to create a Jenkins pipeline that runs npm install, then runs tests with npm test, but only if install succeeds. Which pipeline snippet correctly implements this?
hard
A. sh 'npm install; npm test'
B. try {
sh 'npm install'
sh 'npm test'
} catch (e) {
echo 'Install failed'
}
C. sh 'npm install && npm test'
D. sh 'npm test'
sh 'npm install'
Solution
Step 1: Understand command chaining with &&
Using npm install && npm test runs tests only if install succeeds.
Step 2: Compare with other options
sh 'npm install; npm test' runs test regardless because ';' executes the next command irrespective of exit code. try {
sh 'npm install'
sh 'npm test'
} catch (e) {
echo 'Install failed'
} uses try-catch but Jenkins declarative pipeline syntax does not support this directly. sh 'npm test'
sh 'npm install' runs test before install, which is wrong order.
Final Answer:
sh 'npm install && npm test' -> Option C
Quick Check:
Use && to run second command only if first succeeds = B [OK]
Hint: Chain commands with && to run second only if first succeeds [OK]
Common Mistakes:
Using ';' instead of '&&' to chain commands
Using try-catch incorrectly in Jenkinsfile
Running tests before installing dependencies
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.