top of page
RenshiiBG-Planes-1-Banner.jpg

Setup Gitlab for CI/CD


Introduction


To set up Pytest automation code in GitLab and execute it in a CI/CD pipeline after the application code is checked in and the build has passed, follow these steps: 


Step 1: Organize Your Repository. 

Make sure your GitLab repository is organized as the structure shown below.



Step 2:  Create a .gitlab-ci.yml File.

Create a .gitlab-ci.yml file in the root of your repository. This file defines the CI/CD pipeline stages and jobs. Please see the basic example.



In this example, the pipeline has two stages: build and test. The build stage is a placeholder for your application code build process, and the test stage installs dependencies and runs Pytest on the test files. 



Step 3: Update Pytest Configuration. 

Ensure your Pytest configuration is set up to discover and run tests. Create or update a pytest.ini or setup.cfg file in the root of your repository as shown below.



This configuration tells Pytest to look for test files in the tests/ directory. 



Step 4:  Commit and Push Changes. 

Commit the .gitlab-ci.yml file, Pytest configuration, and any other changes. Push the changes to your GitLab repository.



Step 5:  Monitor CI/CD Pipeline Execution. 

Visit your GitLab project, navigate to the "CI / CD > Pipelines" section, and you should see the pipeline running. GitLab will automatically trigger the pipeline when changes are pushed. 



Step 6:  Customize as Needed. 

Customize the .gitlab-ci.yml file based on your specific requirements. You might need to adjust the script section to include any additional steps or environment setup required for your application and tests. 


Important Notes: 

  • Ensure that your GitLab Runner has the necessary permissions to install dependencies and execute tests.

  • Adjust the Pytest options (PYTEST_OPTIONS) in the .gitlab-ci.yml file as needed. 

  • Make sure your Pytest tests are organized and follow the Pytest conventions. 


This basic setup provides a starting point, and you can extend it to include more advanced features, such as parallel test execution, test reports, and integration with external services.

19 views0 comments

Recent Posts

See All

Comments


bottom of page