11pipeline {
22 agent any
33
4- // Variables de entorno
5- environment {
6- NODE_VERSION = ' 18'
7- TEST_ENV = ' QA'
8- PLAYWRIGHT_BROWSERS_PATH = " ${ WORKSPACE} \\ ms-playwright"
9- }
4+ environment {
5+ NODE_VERSION = ' 18'
6+ TEST_ENV = ' QA'
7+ PLAYWRIGHT_BROWSERS_PATH = " ${ WORKSPACE} \\ ms-playwright"
8+ }
109
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- }
10+ parameters {
11+ choice(
12+ name : ' BROWSER' ,
13+ choices : [' chromium-ui' , ' firefox-ui' , ' webkit-ui' , ' api-tests' , ' all' ],
14+ description : ' Selecciona el navegador o tipo de test'
15+ )
16+ choice(
17+ name : ' TEST_SUITE' ,
18+ choices : [' all' , ' ui' , ' api' , ' e2e' , ' integration' , ' contract' , ' performance' , ' security' , ' accessibility' , ' visual' ],
19+ description : ' Selecciona la suite de tests'
20+ )
21+ booleanParam(
22+ name : ' HEADED' ,
23+ defaultValue : false ,
24+ description : ' Ejecutar tests con interfaz gráfica'
25+ )
26+ booleanParam(
27+ name : ' UPDATE_SNAPSHOTS' ,
28+ defaultValue : false ,
29+ description : ' Actualizar screenshots base'
30+ )
31+ }
3432
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()
42- }
33+ triggers {
34+ cron(' 0 2 * * *' )
35+ githubPush()
36+ }
4337
44- stages {
45- stage(' 🔍 Checkout' ) {
46- steps {
47- echo ' === Obteniendo código ==='
48- checkout scm
38+ stages {
39+ stage(' 🔍 Checkout' ) {
40+ steps {
41+ echo ' === Obteniendo código ==='
42+ checkout scm
43+ }
4944 }
50- }
51-
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- '''
45+
46+ stage( ' 📦 Install Dependencies ' ) {
47+ steps {
48+ echo ' === Instalando dependencias de Node.js === '
49+ bat '' '
50+ node --version
51+ npm --version
52+ npm ci
53+ '''
54+ }
6055 }
61- }
62-
63- stage( ' 🎭 Install Playwright ' ) {
64- steps {
65- echo ' === Instalando navegadores de Playwright === '
66- bat '''
67- npx playwright install --with-deps
68- '''
56+
57+ stage( ' 🎭 Install Playwright ' ) {
58+ steps {
59+ echo ' === Instalando navegadores de Playwright === '
60+ bat '' '
61+ npx playwright install --with-deps
62+ '''
63+ }
6964 }
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- )
65+
66+ stage(' 🧪 Run Tests' ) {
67+ steps {
68+ script {
69+ echo ' === Ejecutando tests ==='
70+
71+ def testCommand = buildTestCommand(
72+ params. TEST_SUITE ,
73+ params. BROWSER ,
74+ params. HEADED ,
75+ params. UPDATE_SNAPSHOTS
76+ )
77+
78+ echo " Comando: ${ testCommand} "
79+
80+ def testResult = bat(
81+ script : testCommand,
82+ returnStatus : true
83+ )
84+
85+ env. TEST_RESULT = testResult
86+
87+ if (testResult != 0 ) {
88+ echo ' ⚠️ Algunos tests fallaron'
89+ } else {
90+ echo ' ✅ Todos los tests pasaron'
91+ }
92+ }
93+ }
94+ }
95+
96+ stage(' 📊 Generate Reports' ) {
97+ steps {
98+ echo ' === Generando reportes ==='
99+ bat '''
100+ echo "Reportes generados en reports/"
101+ dir reports\\ || echo "No hay reportes"
102+ '''
103+ }
104+ }
105+
106+ stage(' 📸 Archive Artifacts' ) {
107+ steps {
108+ echo ' === Archivando artefactos ==='
83109
84- echo " Comando: ${ testCommand} "
110+ publishHTML([
111+ allowMissing : false ,
112+ alwaysLinkToLastBuild : true ,
113+ keepAll : true ,
114+ reportDir : ' reports/html-report' ,
115+ reportFiles : ' index.html' ,
116+ reportName : ' Playwright Test Report' ,
117+ reportTitles : ' Test Report'
118+ ])
85119
86- // Ejecutar tests y capturar resultado
87- def testResult = bat(
88- script : testCommand ,
89- returnStatus : true
120+ archiveArtifacts(
121+ artifacts : ' test-results/**/*,screenshots/**/* ' ,
122+ allowEmptyArchive : true ,
123+ fingerprint : true
90124 )
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- }
100125 }
101126 }
102- }
103-
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- '''
127+
128+ stage(' 📈 Publish Test Results' ) {
129+ steps {
130+ echo ' === Publicando resultados JUnit ==='
131+
132+ junit(
133+ testResults : ' reports/junit-results.xml' ,
134+ allowEmptyResults : true ,
135+ skipPublishingChecks : false
136+ )
137+ }
111138 }
112139 }
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- ])
128-
129- // Archivar screenshots y videos (si hay fallos)
130- archiveArtifacts(
131- artifacts : ' test-results/**/*,screenshots/**/*' ,
132- allowEmptyArchive : true ,
133- fingerprint : true
134- )
140+
141+ post {
142+ always {
143+ echo ' === Limpieza post-ejecución ==='
135144 }
136- }
137-
138- stage(' 📈 Publish Test Results' ) {
139- steps {
140- echo ' === Publicando resultados JUnit ==='
145+
146+ success {
147+ echo ' ✅ ¡Pipeline ejecutado exitosamente!'
141148
142- // Publicar resultados JUnit
143- junit(
144- testResults : ' reports/junit-results.xml' ,
145- allowEmptyResults : true ,
146- skipPublishingChecks : false
147- )
149+ script {
150+ echo " Tests completados en: ${ currentBuild.durationString} "
151+ }
148152 }
149- }
150- }
151-
152- post {
153- always {
154- echo ' === Limpieza post-ejecución ==='
155- }
156-
157- success {
158- echo ' ✅ ¡Pipeline ejecutado exitosamente!'
159153
160- script {
161- echo " Tests completados en: ${ currentBuild.durationString} "
154+ failure {
155+ echo ' ❌ El pipeline falló'
156+
157+ script {
158+ if (env. TEST_RESULT != ' 0' ) {
159+ echo ' Los tests fallaron. Revisa el reporte HTML.'
160+ }
161+ }
162162 }
163- }
164-
165- failure {
166- echo ' ❌ El pipeline falló'
167163
168- script {
169- if (env. TEST_RESULT != ' 0' ) {
170- echo ' Los tests fallaron. Revisa el reporte HTML.'
171- }
164+ unstable {
165+ echo ' ⚠️ El pipeline es inestable (algunos tests fallaron)'
172166 }
173167 }
174-
175- unstable {
176- echo ' ⚠️ El pipeline es inestable (algunos tests fallaron)'
177- }
178168}
179169
180- // ==================== FUNCIONES AUXILIARES ====================
181-
182170def buildTestCommand (testSuite , browser , headed , updateSnapshots ) {
183171 def command = ' npx playwright test'
184172
185- // Agregar suite específica
186- if (testSuite != ' all' ) {
187- command + = " tests/${ testSuite} /"
188- }
173+ if (testSuite != ' all' ) {
174+ command + = " tests/${ testSuite} /"
175+ }
189176
190- // Agregar proyecto/navegador
191- if (browser != ' all' ) {
192- command + = " --project=${ browser} "
193- }
177+ if (browser != ' all' ) {
178+ command + = " --project=${ browser} "
179+ }
194180
195- // Modo headed
196- if (headed) {
197- command + = ' --headed'
198- }
181+ if (headed) {
182+ command + = ' --headed'
183+ }
199184
200- // Actualizar snapshots
201- if (updateSnapshots) {
202- command + = ' --update-snapshots'
203- }
185+ if (updateSnapshots) {
186+ command + = ' --update-snapshots'
187+ }
204188
205- return command
189+ return command
206190}
0 commit comments