Using Jenkins Pipeline for Continuous Integration and Deployment of PHP Applications
This article provides a step‑by‑step guide on setting up Jenkins Pipeline to automate the continuous integration, testing, and deployment of PHP applications, covering prerequisite installations, plugin configuration, Jenkinsfile creation with stages for checkout, build, test, and deployment, and how to run the pipeline.
Preparation
Before starting, ensure Jenkins is installed and configured, install required plugins (Pipeline, Git, PHP, Deploy to container), and have the PHP source code hosted in a Git repository with proper access.
Creating Jenkins Pipeline
Create a new Pipeline project in Jenkins, set the definition to "Pipeline script from SCM", select Git as the SCM, provide the repository URL, and specify the path to the Jenkinsfile.
Writing Jenkinsfile
The Jenkinsfile defines the CI/CD workflow using four stages: Checkout, Build, Test, and Deploy. The example below shows how to pull code from Git, install dependencies with Composer, run PHPUnit tests, and deploy the built artifact using the Deploy to container plugin.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/example/repo.git'
}
}
stage('Build') {
steps {
sh 'composer install'
}
}
stage('Test') {
steps {
sh 'vendor/bin/phpunit'
}
}
stage('Deploy') {
steps {
deploy adapters: [glassfish(credentialsId: 'credential-id', containerId: 'container-id', contextPath: '', war: '**/*.war')]
}
}
}
}Adjust parameters such as credentialsId and containerId to match your environment.
Running Jenkins Pipeline
After committing the Jenkinsfile, trigger the pipeline by clicking "Build Now" in Jenkins. Monitor the build log to see each stage execute, and verify the PHP application is deployed to the target server.
Conclusion
Using Jenkins Pipeline streamlines and accelerates the continuous packaging and deployment of PHP applications, automating code checkout, dependency installation, testing, and deployment, thereby improving development speed, release quality, and overall efficiency.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.