Skip to content

Commit

Permalink
Update Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak7376 committed Jun 3, 2024
1 parent 9600ef7 commit b0a0657
Showing 1 changed file with 26 additions and 40 deletions.
66 changes: 26 additions & 40 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
pipeline {
agent any

environment {
DOCKER_IMAGE = "robustbase_img"
}

stages {
stage('Checkout') {
steps {
Expand All @@ -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!'
Expand Down

0 comments on commit b0a0657

Please sign in to comment.