Effortlessly Automate Your Builds and Deployments: A Complete Guide to Jenkins Pipelines for Multiple Programming Languages with Real-World Examples

  1. Java pipeline:
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'mvn clean install'
            }
        }
        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
        stage('Deploy') {
            steps {
                sh 'scp target/my-app.war user@prod-server:/opt/tomcat/webapps'
            }
        }
    }
}

  1. Python pipeline:
pipeline {
    agent any
    stages {
        stage('Install') {
            steps {
                sh 'pip install -r requirements.txt'
            }
        }
        stage('Test') {
            steps {
                sh 'pytest'
            }
        }
        stage('Deploy') {
            steps {
                sh 'rsync -avz . user@prod-server:/opt/app'
            }
        }
    }
}

  1. Node.js pipeline:
pipeline {
    agent any
    stages {
        stage('Install') {
            steps {
                sh 'npm install'
            }
        }
        stage('Test') {
            steps {
                sh 'npm test'
            }
        }
        stage('Build') {
            steps {
                sh 'npm run build'
            }
        }
        stage('Deploy') {
            steps {
                sh 'rsync -avz . user@prod-server:/opt/app'
            }
        }
    }
}

  1. Ruby pipeline:
pipeline {
    agent any
    stages {
        stage('Install') {
            steps {
                sh 'bundle install'
            }
        }
        stage('Test') {
            steps {
                sh 'rspec'
            }
        }
        stage('Deploy') {
            steps {
                sh 'cap production deploy'
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *