Building a DevOps Pipeline from Scratch

Introduction

In today's fast-paced software development landscape, DevOps has become an essential practice for teams to deliver high-quality software quickly and efficiently. In this article, we'll build a simple web application from scratch and automate its build, test, and deployment process using Jenkins and JFrog Artifactory.

Jenkins DevOps

Application Overview

Our application, called "HelloDevOps," will be a simple web server that returns "Hello, DevOps!" when accessed. We'll use Flask as the web framework and Python 3.9 as the runtime environment.

Step 1. Create the Application

We start by creating a new directory for our application and adding the following files:

  • app.py (our Flask application code)
    from flask import Flask
    app = Flask(__name__)
    
    @app.route('/')
    def hello():
        return 'Hello, DevOps!'
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5000)
  • tests.py (unit tests for our application)

Step 2. Create a Jenkins Job

Next, we create a new Jenkins job called "HelloDevOps" with the following configuration:

  • Source Code Management: Git (pointing to our application repository)
  • Build: Execute shell command pip install -r requirements.txt (install dependencies)
  • Build: Execute shell command python tests.py (run unit tests)
  • Post-build Actions: Deploy artifacts to JFrog Artifactory (we'll configure this later)

Step 3. Create an Artifactory Repository

We create a new repository in JFrog Artifactory called "hello-devops" with the following configuration:

  • Repository Type: Generic
  • Package Type: Python
  • Layout: Maven 2

Step 4. Configure Jenkins to Deploy to Artifactory

In our Jenkins job, we add a post-build action to deploy our application to Artifactory:

  • Deploy artifacts to Artifactory: Select our "hello-devops" repository and specify the artifact to deploy (our app.py file)

Step 5. Run the Jenkins Job

We trigger the Jenkins job to build, test, and deploy our application to Artifactory.

Step 6. Verify the Deployment

Finally, we access our application by visiting http://localhost:5000 in a web browser. We should see "Hello, DevOps!" displayed.

Conclusion

In this article, we've successfully built a simple web application from scratch, automated its build, test, and deployment process using Jenkins, and stored its artifacts in JFrog Artifactory. This illustrates the DevOps workflow and the integration between Jenkins and Artifactory. By following these steps, you can create your own DevOps pipeline and streamline your software development process.


Similar Articles