Skip to main content

Jenkinsfile-laravel.md

Template pipeline for Laravel projects with Composer install, database migration, PHPUnit tests, Docker image build, and push.

Pipeline

pipeline {
agent any
environment {
REGISTRY = "your.registry.example.com/my-laravel-app"
REGISTRY_CREDENTIALS = 'registry-credentials-id'
}
stages {
stage('Checkout') { steps { checkout scm } }
stage('Install') {
steps { sh 'composer install --no-interaction --prefer-dist --optimize-autoloader' }
}
stage('Env & Migrate') {
steps {
sh 'php artisan migrate --force'
}
}
stage('Test') { steps { sh 'vendor/bin/phpunit' } }
stage('Build Image') { steps { sh 'docker build -t ${REGISTRY}:${BUILD_NUMBER} .' } }
stage('Push') {
steps {
withCredentials([usernamePassword(credentialsId: env.REGISTRY_CREDENTIALS, usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $PASS | docker login -u $USER --password-stdin your.registry.example.com'
sh 'docker push ${REGISTRY}:${BUILD_NUMBER}'
}
}
}
}
}

Copy the pipeline into your repository root as Jenkinsfile and adjust registry/credentials/build commands for your project.