-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
97 lines (81 loc) · 3.31 KB
/
Jenkinsfile
File metadata and controls
97 lines (81 loc) · 3.31 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
pipeline {
agent {
docker {
image 'php:8.2-cli'
args '-u root'
}
}
environment {
REPO = "RonDevHub/Mini-Badges"
CONTEXT = "jenkins/badge-test"
BADGE_FILE = "output.svg"
}
stages {
stage('Build Trigger Check') {
steps {
echo "🚀 Pipeline durch Push ausgelöst"
}
}
stage('Checkout') {
steps {
checkout scm
}
}
stage('Badge Test') {
steps {
script {
// Commit-Hash direkt aus Jenkins (kein Git im Container nötig)
def commit = env.GIT_COMMIT
echo "🔑 Commit: ${commit}"
withCredentials([string(credentialsId: 'forgejo-token-string', variable: 'GITEA_TOKEN')]) {
// Pending Status an Forgejo
sh """
curl -X POST "https://commitcloud.net/api/v1/repos/${REPO}/statuses/${commit}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GITEA_TOKEN" \
-d '{ "state": "pending", "description": "Badge Test running", "context": "${CONTEXT}" }'
"""
// Badge erzeugen
sh "php badge.php type=static left=Hallo right=Welt style=flat > ${BADGE_FILE}"
// Badge prüfen
def status = fileExists(BADGE_FILE) ? "success" : "failure"
echo "📦 Badge File Status: ${status}"
// Ergebnis an Forgejo
sh """
curl -X POST "https://commitcloud.net/api/v1/repos/${REPO}/statuses/${commit}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GITEA_TOKEN" \
-d '{ "state": "${status}", "description": "Badge Test Result", "context": "${CONTEXT}" }'
"""
if (status == "failure") {
error("❌ Badge Test fehlgeschlagen")
}
}
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'output.svg', allowEmptyArchive: true
}
success {
withCredentials([string(credentialsId: 'matrix-token', variable: 'MATRIX_TOKEN')]) {
sh """
curl -XPOST "https://matrix.s3cr.net/_matrix/client/v3/rooms/!fPQlDFSrZpnlfnEfYH:matrix.s3cr.net/send/m.room.message?access_token=$MATRIX_TOKEN" \
-H 'Content-Type: application/json' \
-d '{ "msgtype": "m.text", "body": "✅ Jenkins Pipeline erfolgreich abgeschlossen!" }'
"""
}
}
failure {
withCredentials([string(credentialsId: 'matrix-token', variable: 'MATRIX_TOKEN')]) {
sh """
curl -XPOST "https://matrix.s3cr.net/_matrix/client/v3/rooms/!fPQlDFSrZpnlfnEfYH:matrix.s3cr.net/send/m.room.message?access_token=$MATRIX_TOKEN" \
-H 'Content-Type: application/json' \
-d '{ "msgtype": "m.text", "body": "❌ Jenkins Pipeline fehlgeschlagen — Logs prüfen!" }'
"""
}
}
}
}