mirror of
https://github.com/sanjeed5/awesome-cursor-rules-mdc.git
synced 2026-11-30 23:04:59 +08:00
Regenerate all MDC rules with fresh Exa data and December 2025 best practices
- Refreshed all 241 library rules with current best practices - Updated Exa search results for all libraries with 2025 content - Fixed --regenerate-all flag logic to properly process all libraries - Removed duplicate astro entry in rules.json (merged tags) - Added missing docker.mdc and vim.mdc files - All rules now include modern patterns and anti-patterns - Updated with framework-specific recommendations for 2025 Technical improvements: - Fixed retry_failed_only logic in generate_mdc_files.py - Improved progress tracking for regeneration scenarios - Ensured proper handling of --refresh-exa flag
This commit is contained in:
+308
-178
@@ -1,194 +1,324 @@
|
||||
---
|
||||
description: Comprehensive best practices for Jenkins, covering code organization, security, performance, testing, and common pitfalls. Provides guidelines for writing robust, maintainable, and secure Jenkins pipelines and configurations.
|
||||
globs: Jenkinsfile,*.jenkins,*.groovy
|
||||
description: Definitive guidelines for writing robust, maintainable, and secure Jenkins Pipelines using modern best practices.
|
||||
globs: **/*
|
||||
---
|
||||
# Jenkins Library Best Practices and Coding Standards
|
||||
# jenkins Best Practices
|
||||
|
||||
This document outlines best practices for developing and maintaining Jenkins pipelines and configurations to ensure robustness, security, and efficiency.
|
||||
This guide outlines essential best practices for developing Jenkins Pipelines. Adhere to these rules to ensure your CI/CD processes are efficient, secure, and maintainable.
|
||||
|
||||
## 1. Code Organization and Structure
|
||||
|
||||
* **Directory Structure:**
|
||||
* `/vars/`: Store shared pipeline libraries (Groovy files). Each file in this directory represents a callable method.
|
||||
* `/resources/`: Place non-Groovy resources like configuration files or scripts used by the pipeline.
|
||||
* `Jenkinsfile`: The primary pipeline definition file, typically at the root of the repository.
|
||||
* `.cursor/rules`: Where .mdc rule files should be
|
||||
* **File Naming Conventions:**
|
||||
* Pipeline definitions: `Jenkinsfile` (recommended), or `<project-name>.jenkins`
|
||||
* Shared libraries: `lowercaseCamelCase.groovy` (e.g., `buildImage.groovy`)
|
||||
* Resource files: Descriptive names with appropriate extensions (e.g., `settings.xml`, `deploy.sh`)
|
||||
* **Module Organization:**
|
||||
* Break down complex pipelines into smaller, reusable shared libraries.
|
||||
* Group related functions within shared libraries into logical modules.
|
||||
* Use descriptive names for shared libraries to indicate their purpose (e.g., `awsUtils.groovy`, `dockerBuild.groovy`).
|
||||
* **Component Architecture:**
|
||||
* Adopt a modular design for shared libraries, separating concerns and promoting reusability.
|
||||
* Create abstract functions that can be extended or customized for specific projects.
|
||||
* Avoid tightly coupling shared libraries to specific projects or environments.
|
||||
* **Code Splitting Strategies:**
|
||||
* Split long `Jenkinsfile`s into multiple files using `load()` or shared libraries. This improves readability and maintainability.
|
||||
* Delegate complex tasks to external scripts or tools invoked from the pipeline.
|
||||
* Use environment variables to parameterize pipeline behavior and avoid hardcoding values.
|
||||
### 1.1. Always use "Pipeline as Code"
|
||||
Store your `Jenkinsfile` in the root of your project's SCM repository. This enables version control, peer review, and a traceable history for your pipeline definitions.
|
||||
|
||||
❌ BAD: Defining pipelines directly in the Jenkins UI.
|
||||
```groovy
|
||||
// No Jenkinsfile in SCM, pipeline defined in UI.
|
||||
// Hard to track changes, no version history.
|
||||
```
|
||||
|
||||
✅ GOOD: Store `Jenkinsfile` in SCM.
|
||||
```groovy
|
||||
// Jenkinsfile at project root (e.g., my-app/Jenkinsfile)
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'mvn clean package'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 1.2. Prefer Declarative Pipeline Syntax
|
||||
Declarative syntax is more readable, structured, and offers built-in validation. Use it for all new pipelines unless a specific, advanced scenario *absolutely* requires Scripted syntax.
|
||||
|
||||
❌ BAD: Using Scripted Pipeline for standard CI/CD flows.
|
||||
```groovy
|
||||
// Scripted Pipeline (less readable, harder to validate)
|
||||
node('agent-label') {
|
||||
stage('Checkout') {
|
||||
checkout scm
|
||||
}
|
||||
stage('Build') {
|
||||
sh 'npm install'
|
||||
sh 'npm run build'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ GOOD: Use Declarative Pipeline Syntax.
|
||||
```groovy
|
||||
// Declarative Pipeline (structured, readable, validated)
|
||||
pipeline {
|
||||
agent { label 'agent-label' }
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'npm install'
|
||||
sh 'npm run build'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 1.3. Leverage Shared Libraries for Reusability
|
||||
Extract common, complex, or security-sensitive logic into Jenkins Shared Libraries. This promotes code reuse, centralizes maintenance, and keeps `Jenkinsfile`s clean and focused on orchestration. Avoid `script` tags in Declarative Pipelines; they are a strong indicator that a shared library is needed.
|
||||
|
||||
❌ BAD: Duplicating complex logic or using `script` tags in `Jenkinsfile`.
|
||||
```groovy
|
||||
// Jenkinsfile with inline script for complex logic
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
script { // Avoid script tags in Declarative
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
sh "deploy-prod.sh --version ${env.BUILD_ID}"
|
||||
} else {
|
||||
sh "deploy-staging.sh --branch ${env.BRANCH_NAME}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ GOOD: Use Shared Libraries for common logic.
|
||||
```groovy
|
||||
// Jenkinsfile using a shared library step
|
||||
// (Assuming 'myOrg.deployApp' is defined in a shared library)
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Deploy Staging') {
|
||||
when { expression { env.BRANCH_NAME != 'main' } }
|
||||
steps {
|
||||
myOrg.deployApp('staging') // Reusable, tested logic
|
||||
}
|
||||
}
|
||||
stage('Deploy Production') {
|
||||
when { expression { env.BRANCH_NAME == 'main' } }
|
||||
steps {
|
||||
myOrg.deployApp('prod') // Reusable, tested logic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 1.4. Use Organization Folders or Multibranch Pipelines
|
||||
Automate job creation and management. Organization Folders (for GitHub, GitLab, Bitbucket organizations) are preferred as they automatically discover repositories and create Multibranch Pipelines. If not possible, use Multibranch Pipelines directly. This ensures every branch gets its own pipeline run.
|
||||
|
||||
❌ BAD: Manually creating Freestyle jobs or single Pipeline jobs per branch.
|
||||
```groovy
|
||||
// Manual job creation: time-consuming, error-prone, not scalable.
|
||||
// This is a UI-driven anti-pattern, no code example.
|
||||
```
|
||||
|
||||
✅ GOOD: Configure Organization Folders or Multibranch Pipelines.
|
||||
```groovy
|
||||
// Jenkins is configured to scan a GitHub Organization,
|
||||
// automatically creating Multibranch Pipelines for each repository.
|
||||
// The Jenkinsfile within each repository defines the pipeline.
|
||||
```
|
||||
|
||||
## 2. Common Patterns and Anti-patterns
|
||||
|
||||
* **Design Patterns:**
|
||||
* **Strategy Pattern:** Implement different build or deployment strategies based on input parameters.
|
||||
* **Template Method Pattern:** Define a base pipeline structure with customizable steps for specific projects.
|
||||
* **Facade Pattern:** Create a simplified interface to complex systems or tools.
|
||||
* **Recommended Approaches:**
|
||||
* Use declarative pipelines for improved readability and maintainability.
|
||||
* Employ shared libraries to promote code reuse and consistency.
|
||||
* Automate testing and security scanning within the pipeline.
|
||||
* Monitor pipeline performance and optimize for speed and efficiency.
|
||||
* Use a version control system (e.g., Git) to track changes to pipeline definitions and shared libraries.
|
||||
* **Anti-patterns and Code Smells:**
|
||||
* **Large, monolithic `Jenkinsfile`s:** Difficult to read, maintain, and debug.
|
||||
* **Hardcoding sensitive information:** Compromises security and makes pipelines inflexible.
|
||||
* **Lack of error handling:** Pipelines fail without clear error messages or recovery mechanisms.
|
||||
* **Excessive Groovy scripting:** Can impact performance and increase complexity. Delegate tasks to external tools where possible.
|
||||
* **Ignoring security vulnerabilities:** Exposes systems to potential attacks.
|
||||
* **Duplicated code across pipelines:** Indicates a need for shared libraries.
|
||||
* **State Management:**
|
||||
* Use environment variables to store pipeline state.
|
||||
* Persist state to external systems (e.g., databases, artifact repositories) for long-running pipelines.
|
||||
* Avoid relying on global variables or mutable shared state.
|
||||
* **Error Handling:**
|
||||
* Use `try...catch` blocks to handle exceptions and prevent pipeline failures.
|
||||
* Log error messages with sufficient detail to facilitate debugging.
|
||||
* Implement retry mechanisms for transient errors.
|
||||
* Use the `error` step to explicitly fail the pipeline with a custom message.
|
||||
* Consider using `unstash` with error handling to clean up temporary files.
|
||||
### 2.1. Execute All Material Work on Agents
|
||||
Never run heavy tasks directly on the Jenkins controller (master). The controller is for orchestration; agents perform the actual build, test, and deployment work. This prevents controller overload and ensures isolated, reproducible environments.
|
||||
|
||||
❌ BAD: Running `sh` or `bat` commands outside an `agent` block.
|
||||
```groovy
|
||||
pipeline {
|
||||
// agent none is implicit here, or explicitly set
|
||||
stages {
|
||||
stage('Bad Stage') {
|
||||
steps {
|
||||
// This runs on the Jenkins controller!
|
||||
sh 'echo "This is bad, running on master!"'
|
||||
sh 'mvn clean install' // Very bad!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ GOOD: Always specify an `agent` for stages performing work.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent none // Controller only orchestrates
|
||||
stages {
|
||||
stage('Good Stage') {
|
||||
agent { label 'build-agent' } // Work runs on a dedicated agent
|
||||
steps {
|
||||
sh 'echo "This is good, running on an agent!"'
|
||||
sh 'mvn clean install'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2. Place `input` Steps Outside `agent` Blocks and Wrap with `timeout`
|
||||
`input` steps pause pipeline execution, holding an expensive agent resource unnecessarily. Always place `input` steps in a stage with `agent none` or outside any agent-bound stage. Furthermore, wrap `input` steps with a `timeout` to prevent pipelines from hanging indefinitely, ensuring proper cleanup.
|
||||
|
||||
❌ BAD: `input` inside an `agent` or without a `timeout`.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Build') {
|
||||
agent { label 'build-agent' }
|
||||
steps {
|
||||
sh 'build-app.sh'
|
||||
}
|
||||
}
|
||||
stage('Manual Approval (Bad)') {
|
||||
agent { label 'build-agent' } // Agent held unnecessarily
|
||||
steps {
|
||||
input message: 'Approve deployment?' // No timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ GOOD: `input` outside `agent` and with `timeout`.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Build') {
|
||||
agent { label 'build-agent' }
|
||||
steps {
|
||||
sh 'build-app.sh'
|
||||
}
|
||||
}
|
||||
stage('Manual Approval (Good)') {
|
||||
// No agent specified, runs on controller (lightweight)
|
||||
options {
|
||||
timeout(time: 10, unit: 'MINUTES') // Fails if no approval in 10 min
|
||||
}
|
||||
steps {
|
||||
input message: 'Approve deployment to Production?'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
agent { label 'deploy-agent' }
|
||||
steps {
|
||||
sh 'deploy-app.sh'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3. Acquire Agents Within Parallel Branches
|
||||
When using `parallel` stages, ensure each branch acquires its own agent. This maximizes parallelism and prevents executor starvation, significantly speeding up pipelines with independent tasks (e.g., parallel test suites).
|
||||
|
||||
❌ BAD: Parallel stages sharing a single agent or not explicitly acquiring agents.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent { label 'single-agent' } // All parallel stages share this agent
|
||||
stages {
|
||||
stage('Run Tests') {
|
||||
parallel {
|
||||
stage('Unit Tests') {
|
||||
steps { sh 'run-unit-tests.sh' }
|
||||
}
|
||||
stage('Integration Tests') {
|
||||
steps { sh 'run-integration-tests.sh' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ GOOD: Each parallel branch acquires its own agent.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Run Tests in Parallel') {
|
||||
parallel {
|
||||
stage('Unit Tests') {
|
||||
agent { label 'unit-test-agent' } // Dedicated agent
|
||||
steps { sh 'run-unit-tests.sh' }
|
||||
}
|
||||
stage('Integration Tests') {
|
||||
agent { label 'integration-test-agent' } // Dedicated agent
|
||||
steps { sh 'run-integration-tests.sh' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Performance Considerations
|
||||
|
||||
* **Optimization Techniques:**
|
||||
* Parallelize build and test stages to reduce overall execution time.
|
||||
* Use caching to avoid redundant downloads and computations.
|
||||
* Optimize Groovy code for performance (e.g., avoid unnecessary iterations).
|
||||
* Use lightweight agents with sufficient resources to handle the workload.
|
||||
* Leverage build accelerators and distributed build systems.
|
||||
* **Memory Management:**
|
||||
* Avoid loading large files into memory using `JsonSlurper` or `XmlSlurper`. Use `sh` step with tools like `jq` or `xmllint` instead.
|
||||
* Limit the use of global variables and shared state to reduce memory consumption.
|
||||
* Monitor agent memory usage and adjust agent resources accordingly.
|
||||
* **Bundle Size Optimization:** (Not directly applicable to Jenkins pipelines but relevant to applications built by Jenkins)
|
||||
* Minimize dependencies and remove unused code.
|
||||
* Use code splitting to load only the necessary code modules.
|
||||
* Compress artifacts before archiving or deploying them.
|
||||
* **Lazy Loading:** (Not directly applicable to Jenkins pipelines themselves, but is related to web applications that are built using Jenkins).
|
||||
* Load resources on demand instead of upfront to reduce initial load time.
|
||||
* Defer the execution of non-critical tasks until they are needed.
|
||||
* Utilize asynchronous operations to avoid blocking the pipeline execution.
|
||||
### 3.1. Optimize Agent Provisioning
|
||||
Use ephemeral, container-based agents (e.g., Kubernetes agents, Docker agents) that are spun up on demand and torn down after use. This ensures clean, reproducible environments and prevents "executor starvation" by dynamically scaling resources.
|
||||
|
||||
## 4. Security Best Practices
|
||||
❌ BAD: Long-lived, manually configured agents that accumulate state.
|
||||
```groovy
|
||||
// Agent setup is outside Jenkinsfile, but pipeline relies on a
|
||||
// 'static-agent' that might be busy or have stale state.
|
||||
agent { label 'static-agent' }
|
||||
```
|
||||
|
||||
* **Common Vulnerabilities:**
|
||||
* **Cross-Site Scripting (XSS):** Sanitize user input to prevent malicious code injection.
|
||||
* **Cross-Site Request Forgery (CSRF):** Enable CSRF protection to prevent unauthorized requests.
|
||||
* **Remote Code Execution (RCE):** Avoid executing untrusted code within the pipeline.
|
||||
* **Credential Theft:** Protect sensitive credentials using Jenkins' credential management system.
|
||||
* **Unauthorized Access:** Implement role-based access control to restrict access to sensitive resources.
|
||||
* **Input Validation:**
|
||||
* Validate all user inputs to prevent malicious code injection and data corruption.
|
||||
* Use parameterized builds with predefined choices to limit user input.
|
||||
* Encode or escape special characters to prevent interpretation as code.
|
||||
* **Authentication and Authorization:**
|
||||
* Enable security and configure authentication using Jenkins' built-in user database or an external identity provider (e.g., LDAP, Active Directory).
|
||||
* Implement role-based access control (RBAC) to restrict access to sensitive resources and operations.
|
||||
* Use the principle of least privilege to grant only the necessary permissions to users and groups.
|
||||
* Regularly audit user permissions and remove unnecessary accounts.
|
||||
* **Data Protection:**
|
||||
* Use Jenkins' credential management system to securely store passwords, API keys, and other sensitive information.
|
||||
* Encrypt sensitive data at rest and in transit.
|
||||
* Mask sensitive information in build logs to prevent exposure.
|
||||
* Rotate credentials regularly to minimize the impact of potential breaches.
|
||||
* **Secure API Communication:**
|
||||
* Use HTTPS to encrypt communication between Jenkins and other systems.
|
||||
* Authenticate all API requests using secure tokens or credentials.
|
||||
* Limit API access to authorized users or systems.
|
||||
* Rate-limit API requests to prevent denial-of-service attacks.
|
||||
✅ GOOD: Use dynamic, containerized agents.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent {
|
||||
kubernetes {
|
||||
cloud 'kubernetes'
|
||||
yaml """
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: jnlp
|
||||
image: 'jenkins/jnlp-agent:latest'
|
||||
args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
|
||||
- name: maven
|
||||
image: 'maven:3.8.1-jdk-11'
|
||||
command: ['cat']
|
||||
tty: true
|
||||
"""
|
||||
container 'maven'
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'mvn clean package'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Testing Approaches
|
||||
### 3.2. Implement Caching for Dependencies
|
||||
Cache build dependencies (e.g., Maven local repository, npm modules) to significantly reduce build times. Use Jenkins' built-in caching mechanisms or leverage agent-specific caching where available (e.g., Docker layer caching, Kubernetes persistent volumes).
|
||||
|
||||
* **Unit Testing:**
|
||||
* Test individual functions or modules in isolation.
|
||||
* Use mocking and stubbing to isolate dependencies.
|
||||
* Write unit tests for shared libraries to ensure they function correctly.
|
||||
* **Integration Testing:**
|
||||
* Test the interaction between different components or services.
|
||||
* Verify that shared libraries integrate correctly with the pipeline.
|
||||
* Use containerization to create isolated test environments.
|
||||
* **End-to-End Testing:**
|
||||
* Test the entire pipeline workflow from start to finish.
|
||||
* Simulate real-world scenarios and user interactions.
|
||||
* Use automated testing tools to execute end-to-end tests.
|
||||
* **Test Organization:**
|
||||
* Organize tests into logical suites based on functionality or component.
|
||||
* Use descriptive names for test cases to indicate their purpose.
|
||||
* Run tests automatically as part of the pipeline.
|
||||
* Generate test reports and track test results over time.
|
||||
* **Mocking and Stubbing:**
|
||||
* Use mocking frameworks to create mock objects that simulate the behavior of dependencies.
|
||||
* Stub external services or APIs to isolate the system under test.
|
||||
* Use environment variables to configure mocking behavior.
|
||||
|
||||
## 6. Common Pitfalls and Gotchas
|
||||
|
||||
* **Frequent Mistakes:**
|
||||
* Failing to secure Jenkins instance.
|
||||
* Overusing Groovy scripting leading to performance degradation.
|
||||
* Not using shared libraries for reusable code.
|
||||
* Hardcoding credentials and other secrets.
|
||||
* Lack of proper error handling.
|
||||
* Ignoring pipeline performance monitoring.
|
||||
* **Edge Cases:**
|
||||
* Handling concurrent builds and resource contention.
|
||||
* Dealing with flaky tests and intermittent failures.
|
||||
* Managing large files and artifacts within the pipeline.
|
||||
* Supporting different operating systems and environments.
|
||||
* **Version-Specific Issues:**
|
||||
* Compatibility issues between Jenkins versions and plugins.
|
||||
* Deprecated APIs and features.
|
||||
* Security vulnerabilities in older versions.
|
||||
* **Compatibility Concerns:**
|
||||
* Ensure compatibility between Jenkins and the tools and technologies used in the pipeline (e.g., Docker, Kubernetes, AWS).
|
||||
* Test pipelines on different platforms to ensure cross-platform compatibility.
|
||||
* **Debugging Strategies:**
|
||||
* Use build logs and console output to diagnose pipeline failures.
|
||||
* Add debug statements to Groovy code to trace execution flow.
|
||||
* Use remote debugging tools to step through pipeline execution.
|
||||
* Reproduce pipeline failures locally to isolate the cause.
|
||||
* Utilize the `script` step with caution for complex logic, ensuring proper error handling.
|
||||
* Review plugin documentation for common issues and troubleshooting tips.
|
||||
|
||||
## 7. Tooling and Environment
|
||||
|
||||
* **Recommended Development Tools:**
|
||||
* IDE with Groovy support (e.g., IntelliJ IDEA, Eclipse).
|
||||
* Version control system (e.g., Git).
|
||||
* Build automation tools (e.g., Maven, Gradle).
|
||||
* Testing frameworks (e.g., JUnit, TestNG).
|
||||
* Containerization tools (e.g., Docker).
|
||||
* **Build Configuration:**
|
||||
* Use parameterized builds to allow users to customize build behavior.
|
||||
* Define build triggers to automatically start builds on code changes or schedule.
|
||||
* Configure post-build actions to archive artifacts, send notifications, or deploy the application.
|
||||
* Use the `buildDiscarder` directive to clean up old builds and save disk space.
|
||||
* **Linting and Formatting:**
|
||||
* Use a Groovy linter to enforce coding standards and identify potential errors.
|
||||
* Format Groovy code consistently to improve readability.
|
||||
* Use tools like `groovy-lint` or IDE plugins for linting and formatting.
|
||||
* **Deployment:**
|
||||
* Use deployment plugins to automate the deployment process.
|
||||
* Implement blue-green deployments or rolling deployments to minimize downtime.
|
||||
* Use feature flags to decouple deployment from release.
|
||||
* Use a cloud-native deployment strategy (e.g., Kubernetes) for scalable and resilient deployments.
|
||||
* **CI/CD Integration:**
|
||||
* Integrate Jenkins with other CI/CD tools (e.g., SonarQube, Artifactory).
|
||||
* Use webhooks to trigger builds from version control systems.
|
||||
* Monitor pipeline performance and identify areas for improvement.
|
||||
* Implement continuous feedback loops to improve the quality of the application and the pipeline.
|
||||
* Leverage Infrastructure as Code (IaC) tools such as Terraform to create ephemeral testing and build environments
|
||||
|
||||
By following these best practices, developers can create robust, maintainable, and secure Jenkins pipelines and configurations that streamline the software development process and improve the quality of the application.
|
||||
❌ BAD: Re-downloading all dependencies on every build.
|
||||
```groovy
|
||||
pipeline {
|
||||
agent { label 'build-agent' }
|
||||
stages {
|
||||
stage('Install Dependencies') {
|
||||
steps {
|
||||
sh 'npm install' // Downloads everything every time
|
||||
Reference in New Issue
Block a user