From b0a06573735f2dafec987046476e441d82af823d Mon Sep 17 00:00:00 2001 From: DeepakYadav <41716815+deepak7376@users.noreply.github.com> Date: Tue, 4 Jun 2024 00:42:44 +0530 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 66 +++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index dc74fe3..b6c0d1e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,10 +1,6 @@ pipeline { agent any - environment { - DOCKER_IMAGE = "robustbase_img" - } - stages { stage('Checkout') { steps { @@ -13,59 +9,49 @@ pipeline { } } - stage('Build Docker Image') { + stage('Install Dependencies') { steps { - script { - // Create Dockerfile dynamically - writeFile file: 'Dockerfile', text: ''' - FROM python:3.8-slim - - WORKDIR /app - - # Copy requirements file - COPY requirements.txt . - - # Install dependencies - RUN pip install --no-cache-dir -r requirements.txt - - # Copy requirements-dev file - COPY requirements-dev.txt . - - # Install dev dependencies - RUN pip install --no-cache-dir -r requirements-dev.txt - - # Copy the rest of the application - COPY . . - - # Command to run tests - CMD ["pytest", "tests/"] - ''' - - // Build Docker image - sh 'docker build -t ${DOCKER_IMAGE} .' - } + // Install Python dependencies + sh ''' + # Create a virtual environment + python3 -m venv venv + + # Activate virtual environment + source venv/bin/activate + + # Install dependencies + pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-dev.txt + ''' } } stage('Run Tests') { steps { - // Run Docker container and execute pytest - sh 'docker run --rm ${DOCKER_IMAGE}' + // Run tests using pytest + sh ''' + # Activate virtual environment + source venv/bin/activate + + # Run pytest + pytest tests/ + ''' } } stage('Cleanup') { steps { - // Remove Docker image - sh 'docker rmi ${DOCKER_IMAGE}' + // Clean up the workspace + cleanWs() } } } post { always { - // Clean up workspace after build - cleanWs() + // Clean up the virtual environment if it exists + sh 'rm -rf venv' } success { echo 'Build completed successfully!'