Set up a Jenkins pipeline to automate the testing and deployment of a simple Python web application.
- Install Jenkins on a virtual machine or use a cloud-based Jenkins service.
- Configure Jenkins with Python and any necessary libraries.
- Fork the provided Python web application repository on GitHub.
- Clone the forked repository into your Jenkins server.
- Create a
Jenkinsfile
in the root of your Python application repository. - Define a pipeline with the following stages:
- Build: Install dependencies using pip.
- Test: Run unit tests using a testing framework like pytest.
- Deploy: If tests pass, deploy the application to a staging environment.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
// Install dependencies using pip
sh 'pip install -r requirements.txt'
}
}
}
stage('Test') {
steps {
script {
// Run unit tests using pytest
sh 'pytest'
}
}
}
stage('Deploy') {
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
script {
// Deploy to staging environment (replace with your deployment script)
sh './deploy-to-staging.sh'
}
}
}
}
post {
always {
// Clean up or perform any post-build actions here
}
}
}
- Configure the pipeline to trigger a new build whenever changes are pushed to the main branch of the repository.
- Set up a notification system to alert via email when the build process fails or succeeds.
- Document the pipeline process and any prerequisites needed for the setup in a
README.md
file in the repository.
- The URL to the GitHub repository with the
Jenkinsfile
and updatedREADME.md
. - Include screenshots of the Jenkins pipeline showing the build, test, and deployment stages.
Implement a CI/CD workflow using GitHub Actions for a Python application.
- Use a provided Python application repository on GitHub.
- Ensure the repository has a
main
branch and astaging
branch.
- Create a
.github/workflows
directory in your repository. - Inside the directory, create a YAML file to define the workflow.
name: Python CI/CD
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: pytest
deploy-staging:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && git
- Define a workflow that performs the following jobs:
- Install Dependencies: Install all necessary dependencies for the Python application using pip.
- Run Tests: Execute the test suite using a framework like pytest.
- Build: If tests pass, prepare the application for deployment.
- Deploy to Staging: Deploy the application to a staging environment when changes are pushed to the
staging
branch. - Deploy to Production: Deploy the application to production when a release is tagged.
- Use GitHub Secrets to store sensitive information required for deployments (e.g., deployment keys, API tokens).
- Update the
README.md
file with instructions on how the GitHub Actions workflow works and how to configure the necessary secrets.
- The URL to the GitHub repository with the workflow file and updated
README.md
. - Include screenshots of the GitHub Actions workflow runs showing successful execution of all steps.