Home >Backend Development >PHP Tutorial >Jenkins with PHP – Run Your First Pipeline
Jenkins is a widely used open-source automation server that helps automate tasks such as building, testing, and deploying software. In this blog post, we'll walk you through setting up Jenkins with PHP, guiding you through running your first pipeline for both a simple "Hello, World!" example and running a PHP project from a Git repository using Jenkins.
Before you begin, make sure you have:
We'll start with a basic "Hello, World!" pipeline to familiarize ourselves with the Jenkinsfile syntax.
Scroll down to the Pipeline section.
In the Definition field, select Pipeline script.
Paste the following simple pipeline code into the script box:
groovy
pipeline { agent any stages { stage('Hello') { steps { script { echo 'Hello, World!' } } } } }
This simple pipeline script contains a single stage that outputs the string Hello, World! in the Jenkins console.
Next, we will extend our pipeline to checkout code from a GitHub repository and run a PHP script.
If you don't have one yet, create a simple PHP file in a GitHub repository. Here's an example index.php file:
<?php echo 'helloworld'; ?>
Push this file to a repository (e.g., hello-php-jenkins) on GitHub.
In the Pipeline section, choose Pipeline script.
Replace the default pipeline script with the following code:
pipeline { agent any stages { stage('Hello') { steps { script { echo 'Hello, World!' } } } } }
Note: On Linux, you would replace powershell with sh to execute the PHP command.
Congratulations! You've successfully created two Jenkins pipelines:
A basic "Hello, World!" pipeline that simply prints a message.
A PHP Git pipeline that checks out a PHP project from GitHub and runs a PHP script.
By following these steps, you now have the foundation to create more complex PHP-based pipelines with Jenkins. This is just the beginning, and you can integrate testing, deployment, and other automation tasks into your Jenkins pipeline as needed.
Happy Jenkins-ing!
The above is the detailed content of Jenkins with PHP – Run Your First Pipeline. For more information, please follow other related articles on the PHP Chinese website!