@@ -2,190 +2,179 @@ pipeline {
22 agent any
33
44 // Variables de entorno
5- environment {
6- NODE_VERSION = ' 18'
7- TEST_ENV = ' QA'
8- PLAYWRIGHT_BROWSERS_PATH = " ${ WORKSPACE} /ms-playwright"
9- }
5+ environment {
6+ NODE_VERSION = ' 18'
7+ TEST_ENV = ' QA'
8+ PLAYWRIGHT_BROWSERS_PATH = " ${ WORKSPACE} \\ ms-playwright"
9+ }
10+
11+ // Parámetros configurables
12+ parameters {
13+ choice(
14+ name : ' BROWSER' ,
15+ choices : [' chromium-ui' , ' firefox-ui' , ' webkit-ui' , ' api-tests' , ' all' ],
16+ description : ' Selecciona el navegador o tipo de test'
17+ )
18+ choice(
19+ name : ' TEST_SUITE' ,
20+ choices : [' all' , ' ui' , ' api' , ' e2e' , ' integration' , ' contract' , ' performance' , ' security' , ' accessibility' , ' visual' ],
21+ description : ' Selecciona la suite de tests'
22+ )
23+ booleanParam(
24+ name : ' HEADED' ,
25+ defaultValue : false ,
26+ description : ' Ejecutar tests con interfaz gráfica'
27+ )
28+ booleanParam(
29+ name : ' UPDATE_SNAPSHOTS' ,
30+ defaultValue : false ,
31+ description : ' Actualizar screenshots base'
32+ )
33+ }
34+
35+ // Triggers automáticos
36+ triggers {
37+ // Ejecutar diariamente a las 2 AM
38+ cron(' 0 2 * * *' )
1039
11- // Parámetros configurables
12- parameters {
13- choice(
14- name : ' BROWSER' ,
15- choices : [' chromium-ui' , ' firefox-ui' , ' webkit-ui' , ' api-tests' , ' all' ],
16- description : ' Selecciona el navegador o tipo de test'
17- )
18- choice(
19- name : ' TEST_SUITE' ,
20- choices : [' all' , ' ui' , ' api' , ' e2e' , ' integration' , ' contract' , ' performance' , ' security' , ' accessibility' , ' visual' ],
21- description : ' Selecciona la suite de tests'
22- )
23- booleanParam(
24- name : ' HEADED' ,
25- defaultValue : false ,
26- description : ' Ejecutar tests con interfaz gráfica'
27- )
28- booleanParam(
29- name : ' UPDATE_SNAPSHOTS' ,
30- defaultValue : false ,
31- description : ' Actualizar screenshots base'
32- )
40+ // Ejecutar en cada push (requiere GitHub webhook)
41+ githubPush()
42+ }
43+
44+ stages {
45+ stage(' 🔍 Checkout' ) {
46+ steps {
47+ echo ' === Obteniendo código ==='
48+ checkout scm
49+ }
3350 }
3451
35- // Triggers automáticos
36- triggers {
37- // Ejecutar diariamente a las 2 AM
38- cron(' 0 2 * * *' )
39-
40- // Ejecutar en cada push (requiere GitHub webhook)
41- githubPush()
52+ stage(' 📦 Install Dependencies' ) {
53+ steps {
54+ echo ' === Instalando dependencias de Node.js ==='
55+ bat '''
56+ node --version
57+ npm --version
58+ npm ci
59+ '''
60+ }
4261 }
4362
44- stages {
45- stage(' 🔍 Checkout' ) {
46- steps {
47- echo ' === Obteniendo código ==='
48- checkout scm
49- }
50- }
51-
52- stage(' 📦 Install Dependencies' ) {
53- steps {
54- echo ' === Instalando dependencias de Node.js ==='
55- sh '''
56- node --version
57- npm --version
58- npm ci
59- '''
60- }
61- }
62-
63- stage(' 🎭 Install Playwright' ) {
64- steps {
65- echo ' === Instalando navegadores de Playwright ==='
66- sh '''
67- npx playwright install --with-deps
68- '''
69- }
70- }
71-
72- stage(' 🧪 Run Tests' ) {
73- steps {
74- script {
75- echo ' === Ejecutando tests ==='
76-
77- def testCommand = buildTestCommand(
78- params. TEST_SUITE ,
79- params. BROWSER ,
80- params. HEADED ,
81- params. UPDATE_SNAPSHOTS
82- )
83-
84- echo " Comando: ${ testCommand} "
85-
86- // Ejecutar tests y capturar resultado
87- def testResult = sh(
88- script : testCommand,
89- returnStatus : true
90- )
91-
92- // Guardar resultado
93- env. TEST_RESULT = testResult
94-
95- if (testResult != 0 ) {
96- echo ' ⚠️ Algunos tests fallaron'
97- } else {
98- echo ' ✅ Todos los tests pasaron'
99- }
100- }
101- }
102- }
103-
104- stage(' 📊 Generate Reports' ) {
105- steps {
106- echo ' === Generando reportes ==='
107- sh '''
108- echo "Reportes generados en reports/"
109- ls -la reports/ || echo "No hay reportes"
110- '''
111- }
63+ stage(' 🎭 Install Playwright' ) {
64+ steps {
65+ echo ' === Instalando navegadores de Playwright ==='
66+ bat '''
67+ npx playwright install --with-deps
68+ '''
11269 }
113-
114- stage(' 📸 Archive Artifacts' ) {
115- steps {
116- echo ' === Archivando artefactos ==='
117-
118- // Archivar reportes HTML
119- publishHTML([
120- allowMissing : false ,
121- alwaysLinkToLastBuild : true ,
122- keepAll : true ,
123- reportDir : ' reports/html-report' ,
124- reportFiles : ' index.html' ,
125- reportName : ' Playwright Test Report' ,
126- reportTitles : ' Test Report'
127- ])
70+ }
71+
72+ stage(' 🧪 Run Tests' ) {
73+ steps {
74+ script {
75+ echo ' === Ejecutando tests ==='
12876
129- // Archivar screenshots y videos (si hay fallos)
130- archiveArtifacts(
131- artifacts : ' test-results/**/*,screenshots/**/* ' ,
132- allowEmptyArchive : true ,
133- fingerprint : true
77+ def testCommand = buildTestCommand(
78+ params . TEST_SUITE ,
79+ params . BROWSER ,
80+ params . HEADED ,
81+ params . UPDATE_SNAPSHOTS
13482 )
135- }
136- }
137-
138- stage(' 📈 Publish Test Results' ) {
139- steps {
140- echo ' === Publicando resultados JUnit ==='
14183
142- // Publicar resultados JUnit
143- junit(
144- testResults : ' reports/junit-results.xml' ,
145- allowEmptyResults : true ,
146- skipPublishingChecks : false
84+ echo " Comando: ${ testCommand} "
85+
86+ // Ejecutar tests y capturar resultado
87+ def testResult = bat(
88+ script : testCommand,
89+ returnStatus : true
14790 )
91+
92+ // Guardar resultado
93+ env. TEST_RESULT = testResult
94+
95+ if (testResult != 0 ) {
96+ echo ' ⚠️ Algunos tests fallaron'
97+ } else {
98+ echo ' ✅ Todos los tests pasaron'
99+ }
148100 }
149101 }
150102 }
151103
152- post {
153- always {
154- echo ' === Limpieza post-ejecución ==='
104+ stage(' 📊 Generate Reports' ) {
105+ steps {
106+ echo ' === Generando reportes ==='
107+ bat '''
108+ echo "Reportes generados en reports/"
109+ dir reports\\ || echo "No hay reportes"
110+ '''
111+ }
112+ }
113+
114+ stage(' 📸 Archive Artifacts' ) {
115+ steps {
116+ echo ' === Archivando artefactos ==='
117+
118+ // Archivar reportes HTML
119+ publishHTML([
120+ allowMissing : false ,
121+ alwaysLinkToLastBuild : true ,
122+ keepAll : true ,
123+ reportDir : ' reports/html-report' ,
124+ reportFiles : ' index.html' ,
125+ reportName : ' Playwright Test Report' ,
126+ reportTitles : ' Test Report'
127+ ])
155128
156- // Limpiar workspace si es necesario
157- // cleanWs()
129+ // Archivar screenshots y videos (si hay fallos)
130+ archiveArtifacts(
131+ artifacts : ' test-results/**/*,screenshots/**/*' ,
132+ allowEmptyArchive : true ,
133+ fingerprint : true
134+ )
158135 }
159-
160- success {
161- echo ' ✅ ¡Pipeline ejecutado exitosamente!'
136+ }
137+
138+ stage(' 📈 Publish Test Results' ) {
139+ steps {
140+ echo ' === Publicando resultados JUnit ==='
162141
163- // Notificación de éxito (opcional)
164- script {
165- def totalTests = sh(
166- script : ' cat reports/test-results.json | grep -o \' "tests":[0-9]*\' | grep -o \' [0-9]*\' || echo 0' ,
167- returnStdout : true
168- ). trim()
169-
170- echo " Total de tests ejecutados: ${ totalTests} "
171- }
142+ // Publicar resultados JUnit
143+ junit(
144+ testResults : ' reports/junit-results.xml' ,
145+ allowEmptyResults : true ,
146+ skipPublishingChecks : false
147+ )
172148 }
149+ }
150+ }
151+
152+ post {
153+ always {
154+ echo ' === Limpieza post-ejecución ==='
155+ }
156+
157+ success {
158+ echo ' ✅ ¡Pipeline ejecutado exitosamente!'
173159
174- failure {
175- echo ' ❌ El pipeline falló'
176-
177- // Notificación de fallo (opcional)
178- script {
179- if (env. TEST_RESULT != ' 0' ) {
180- echo ' Los tests fallaron. Revisa el reporte HTML.'
181- }
182- }
160+ script {
161+ echo " Tests completados en: ${ currentBuild.durationString} "
183162 }
163+ }
164+
165+ failure {
166+ echo ' ❌ El pipeline falló'
184167
185- unstable {
186- echo ' ⚠️ El pipeline es inestable (algunos tests fallaron)'
168+ script {
169+ if (env. TEST_RESULT != ' 0' ) {
170+ echo ' Los tests fallaron. Revisa el reporte HTML.'
171+ }
187172 }
188173 }
174+
175+ unstable {
176+ echo ' ⚠️ El pipeline es inestable (algunos tests fallaron)'
177+ }
189178}
190179
191180// ==================== FUNCIONES AUXILIARES ====================
@@ -194,24 +183,24 @@ def buildTestCommand(testSuite, browser, headed, updateSnapshots) {
194183 def command = ' npx playwright test'
195184
196185 // Agregar suite específica
197- if (testSuite != ' all' ) {
198- command + = " tests/${ testSuite} /"
199- }
200-
201- // Agregar proyecto/navegador
202- if (browser != ' all' ) {
203- command + = " --project=${ browser} "
204- }
205-
206- // Modo headed
207- if (headed) {
208- command + = ' --headed'
209- }
210-
211- // Actualizar snapshots
212- if (updateSnapshots) {
213- command + = ' --update-snapshots'
214- }
215-
216- return command
186+ if (testSuite != ' all' ) {
187+ command + = " tests/${ testSuite} /"
188+ }
189+
190+ // Agregar proyecto/navegador
191+ if (browser != ' all' ) {
192+ command + = " --project=${ browser} "
193+ }
194+
195+ // Modo headed
196+ if (headed) {
197+ command + = ' --headed'
198+ }
199+
200+ // Actualizar snapshots
201+ if (updateSnapshots) {
202+ command + = ' --update-snapshots'
203+ }
204+
205+ return command
217206}
0 commit comments