Sling Academy
Home/DevOps/Can you use Jenkins for non-Java projects (Python, JavaScript, PHP, etc.)?

Can you use Jenkins for non-Java projects (Python, JavaScript, PHP, etc.)?

Last updated: February 03, 2024

Introduction

Jenkins, an open-source automation server, is widely recognized for its versatile use in automating all sorts of tasks including building, testing, and deploying software. While it has roots deeply embedded in the Java ecosystem, its scope is not limited to Java projects alone. This article explores how Jenkins can be effectively used for projects written in languages like Python, JavaScript, PHP, among others, and provides a comprehensive walkthrough with various code examples ranging from basic to advanced.

Understanding Jenkins Beyond Java

Initially developed for continuous integration (CI) in Java projects, Jenkins has evolved into a powerful tool supporting Continuous Delivery (CD) for projects in virtually any programming language. This flexibility is largely due to Jenkins’ architecture based on plugins, allowing it to integrate with a variety of development, testing, and deployment tools, irrespective of the language.

Getting Started with Jenkins for Non-Java Projects

To begin using Jenkins for your non-Java project, the first step involves installing Jenkins itself. Jenkins can be installed on multiple operating systems, including Linux, macOS, and Windows. Following installation, the next crucial step is to understand and install the necessary plugins for your specific language and tools. For instance, for Python there’s the ShiningPanda plugin, for JavaScript projects you might look at the NodeJS plugin, and for PHP, the PHP project plugin among others.

Example 1: Configuring Jenkins for a Python Project

To demonstrate using Jenkins with a Python project, let’s start by configuring a simple continuous integration pipeline.

  1. Install the ShiningPanda plugin from the Jenkins plugin management interface.
  2. Create a new Jenkins job and select the ‘Freestyle project’ option.
  3. In the configuration settings, under the Build section, add a build step of ‘Execute Python script’ and enter your Python script or command. For example, to execute a simple script that prints ‘Hello, Jenkins from Python!’, you could add:
    print('Hello, Jenkins from Python!')

Save your settings and run the job. You should see the output in the console log, indicating successful execution.

Example 2: Automating Builds for a JavaScript Node.js Project

Next, let’s automate a build process for a JavaScript project using the NodeJS plugin.

  1. After installing the NodeJS plugin, configure Jenkins to add NodeJS installation under Global Tool Configuration.
  2. Create a new Jenkins job as before, selecting ‘Freestyle project’.
  3. In the Build section, add a step to execute shell commands or Windows batch commands, depending on your OS. Here, you’d typically include commands to install dependencies and build the project, like:
    npm install
    npm build

The build output should be visible in the Jenkins console log upon execution.

Example 3: Setting Up a Continuous Deployment Pipeline for a PHP Application

Finally, setting up a continuous deployment pipeline for a PHP project can enhance efficiency and ensure that every code change is automatically deployed to your production server.

  1. Incorporate a version control system (like Git) by configuring it in the Source Code Management section of your project’s configuration.
  2. Add build steps to validate your code (e.g., using PHP CodeSniffer) and run tests.
  3. For deployment, add a post-build action to transfer files to your server using FTP or SSH. Tools like Publish Over SSH can be utilized here.

Each successful build can now be automatically deployed to your server, streamlining the deployment process.

Conclusion

Jenkins’ flexibility and wide plugin ecosystem make it an excellent choice for automating tasks in non-Java projects as well. Starting with basic configuration and moving towards a fully automated CI/CD pipeline, Jenkins can support projects in Python, JavaScript, PHP, and beyond. Implementing Jenkins into your workflow not only aids in ensuring consistency across builds but also immensely reduces the potential for human error, making your development process more efficient.

Next Article: When NOT to use Jenkins: Exploring Alternatives

Previous Article: Jenkins Web UI: What is the default port and how to change it

Series: Jenkins Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide