dsfai2020 / Task-and-Nutrition-Manager

An agile planning application that tracks tasks, ideas and nutrition goals. This app is designed to assist with everyday productivity, progress tracking and fitness.
1 stars 0 forks source link

Incorporate CI/CD with Jenkins #27

Closed dsfai2020 closed 1 year ago

dsfai2020 commented 1 year ago

Add build steps and configure the python backend first.

dsfai2020 commented 1 year ago

https://www.jenkins.io/ Details here for setup

dsfai2020 commented 1 year ago

How Jenkins can be used to automate a Python project's build and test process.

Assumptions:

Jenkins is installed and running on your system.
The Python project is version-controlled and hosted on a Git repository.

Steps:

Create a new Jenkins Freestyle project:
    Open Jenkins and click on "New Item" to create a new project.
    Enter a project name and select "Freestyle project," then click "OK."

Configure the source code management:
    Under the "Source Code Management" section, choose "Git."
    Enter the Git repository URL and configure credentials if required.

Set up the build step:
    Under the "Build" section, click "Add build step" and select "Execute shell" (for Linux/Mac) or "Execute Windows batch command" (for Windows).
    In the shell or batch command, you can execute the necessary steps to build your Python project. For example:

    bash

# Assuming your project has a virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows, use 'venv\Scripts\activate'
pip install -r requirements.txt
python setup.py install

Configure test execution:

Add another "Execute shell" or "Execute Windows batch command" build step after the build step.
In this step, run your Python project's tests. For example:

    pytest

Save the Jenkins project configuration.

Trigger the Jenkins build:
    Go to your Jenkins project's main page.
    Click "Build Now" to trigger the build. Jenkins will clone the repository, build the project, and run the tests.

View build results:
    After the build is complete, you can check the console output to see if the build and tests were successful.

You can further enhance this setup by adding additional build steps, deploying to different environments, using virtual environments, integrating with third-party tools, and configuring Jenkins to automatically trigger builds on code commits or pull requests.

dsfai2020 commented 1 year ago

Jenkins successfully completed a build. After 20 failed build attempts and troubleshooting in the build steps.
I needed to create a simple unit test for pytest to run.
Jenkins pulls the repository from the jenkins branch then creates a pip env and installs from the requirements (took some custom directory moving) then it eventually runs the test. Jenkins will automatically fail a build if any tests or build steps fail so I decided to create a Passing test just for the sake of getting jenkins to run! Which worked.

image