Repository navigation
Expand file tree
/
Copy pathci-basic.jenkinsfile
More file actions
86 lines (75 loc) · 2.13 KB
/
Copy pathci-basic.jenkinsfile
File metadata and controls
86 lines (75 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
pipeline {
agent any
environment {
IMAGE_NAME = "jgueroit/reto_final_python"
REGISTRY_CREDENTIALS = "docker-hub-creds" // Cambia según el ID en Jenkins
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install Python 3') {
steps {
script {
// Ejecutamos los comandos como root usando 'sudo'
sh '''
echo "Instalando Python 3 y pip3..."
# Usamos sudo para ejecutar como root
sudo apt-get update
sudo apt-get install -y python3 python3-pip
# Verificar la instalación
python3 --version
pip3 --version
'''
}
}
}
stage('Install Dependencies') {
steps {
sh 'pip3 install -r requirements.txt'
}
}
stage('Run Tests') {
steps {
sh 'pytest --cov=app --cov-report=term'
}
}
stage('Linting') {
steps {
sh 'flake8 app tests'
}
}
stage('Build Docker Image') {
steps {
script {
dockerImage = docker.build("${IMAGE_NAME}:${env.BUILD_NUMBER}")
}
}
}
stage('Push Image to Docker Registry') {
when {
anyOf {
branch 'main'
branch 'develop'
branch 'master'
}
}
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', REGISTRY_CREDENTIALS) {
dockerImage.push("latest")
dockerImage.push("${env.BUILD_NUMBER}")
}
}
}
}
}
post {
always {
junit '**/test-results.xml' // opcional
cleanWs()
}
}
}