-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile.groovy
More file actions
142 lines (121 loc) · 4.5 KB
/
Copy pathJenkinsfile.groovy
File metadata and controls
142 lines (121 loc) · 4.5 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
pipeline {
agent any
environment {
PW_IMAGE = 'mcr.microsoft.com/playwright:v1.53.2-jammy'
}
options { timestamps() }
triggers {
cron('0 0 * * *')
// Poll SCM every 5 minutes to detect new commits
// Note: for better performance, configure a webhook in your Git repository
// instead of polling (Settings -> Webhooks in Github/GitLab)
pollSCM('H/5 * * * *') // Comment this out when Webhook is implemented
}
stages {
stage('Determine Build Type') {
steps{
script {
// Check if this build was triggered by the cron schedule (nightly)
def isNightlyBuild = currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').size() > 0
env.IS_NIGHTLY = isNightlyBuild.toString()
env.TEST_SUITE = isNightlyBuild ? 'tests/' : 'tests/login.spec.ts'
echo "==================================================="
if(isNightlyBuild) {
echo "Build Type: NIGHTLY BUILD"
echo "Test Suite: Full Regression (all tests)"
} else {
echo "Build Type: COMMIT-TRIGGERED BUILD"
echo "Test Suite: Smoke tests (login.spec.ts)"
}
echo "==================================================="
}
}
}
stage('Install & Test in Playwright image') {
steps {
script {
withCredentials([
usernamePassword(
credentialsId: 'trello-e2e-valid-user',
usernameVariable: 'E2E_VALID_USER',
passwordVariable: 'E2E_VALID_PASS'
),
usernamePassword(
credentialsId: 'trello-e2e-invalid-user',
usernameVariable: 'E2E_INVALID_USER',
passwordVariable: 'E2E_INVALID_PASS'
),
string(
credentialsId: 'TOTP_SECRET',
variable: 'TOTP_SECRET'
)
]) {
sh '''
set -eux
# Enhanced container cleanup
docker stop pw-tests 2>/dev/null || true
docker rm -f pw-tests 2>/dev/null || true
# Verify it's gone
docker ps -a | grep pw-tests || echo "Container successfully removed"
docker run --name pw-tests --pull=missing --rm \
-e CI=1 \
-e USER_EMAIL=${E2E_VALID_USER} \
-e USER_PASSWORD=${E2E_VALID_PASS} \
-e INVALID_USER_EMAIL=${E2E_INVALID_USER} \
-e INVALID_USER_PASSWORD=${E2E_INVALID_PASS} \
-e TOTP_SECRET=${TOTP_SECRET} \
-e TEST_SUITE=${TEST_SUITE} \
mcr.microsoft.com/playwright:v1.53.2-jammy \
bash -lc "
set -euxo pipefail
if ! command -v git >/dev/null 2>&1; then
apt-get update
apt-get install -y git
fi
rm -rf /work
mkdir -p /work
git clone --branch main --single-branch https://github.com/Lishkon/trello-playwright-demo.git /work
cd /work
npm install
mkdir -p auth
CI=1 npx playwright test ${TEST_SUITE} --reporter=html
"
'''
}
}
}
}
stage('Publish & Archive') {
steps {
script {
sh '''
set -eux
echo "Workspace: $PWD"
# Remove old report directory to prevent nesting
rm -rf playwright-report
# Copy the HTML report from the test container into this workspace
docker cp pw-tests:/work/playwright-report ./playwright-report || echo "No report directory to copy"
# echo "Contents of workspace after docker cp:"
# ls -R .
'''
// Archive the raw report files (optional but useful)
archiveArtifacts artifacts: 'playwright-report/**', fingerprint: true, allowEmptyArchive: true
// Publish HTML report so it shows as a tab in Jenkins
publishHTML(target: [
reportDir: 'playwright-report',
reportFiles: 'index.html',
reportName: 'Playwright HTML Report',
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: true
])
}
}
post {
always {
sh 'docker rm -f pw-tests || true'
}
}
}
}
}