-
Notifications
You must be signed in to change notification settings - Fork 581
Expand file tree
/
Copy pathJenkinsfile.javadocs
More file actions
144 lines (128 loc) · 4.67 KB
/
Copy pathJenkinsfile.javadocs
File metadata and controls
144 lines (128 loc) · 4.67 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
143
144
#!groovy
pipeline {
agent {
label 'git-websites'
}
parameters {
string(name: 'STRUTS_TAG', defaultValue: 'main',
description: 'Struts release tag (e.g. STRUTS_7_2_1) or "main"')
}
options {
buildDiscarder logRotator(numToKeepStr: '5')
timeout(90)
disableConcurrentBuilds()
skipStagesAfterUnstable()
}
tools {
// Provisions `mvn` and JDK 17 on PATH via Jenkins tool installers, matching
// the apache/struts build. Struts 7 requires JDK 17.
jdk 'jdk_17_latest'
maven 'maven_3_latest'
}
environment {
MAVEN_OPTS = '-Xmx2048m -Dhttps.protocols=TLSv1.2 -DfailOnError=false'
}
stages {
stage('Build Struts & Maven site') {
steps {
// Show the tag being built in the build history, next to the build number.
script {
currentBuild.displayName = "#${env.BUILD_NUMBER} ${params.STRUTS_TAG}"
}
sh '''
echo "Building Struts ${STRUTS_TAG} and staging the Maven site"
rm -rf target/struts
git clone https://gitbox.apache.org/repos/asf/struts.git target/struts
cd target/struts
if [ "${STRUTS_TAG}" = "main" ]; then
git checkout main
else
git checkout "tags/${STRUTS_TAG}"
fi
mvn -B -V clean install -DskipTests
# Skip the OWASP dependency-check report: its aggregate goal downloads the
# full NVD CVE database (~360k records) with no API key, blowing the timeout.
# Not needed for the published Maven site.
mvn -B -V site:site site:stage -Ddependency-check.skip=true
'''
}
}
stage('Publish to source/maven') {
steps {
sh '''
echo "Publishing the staged Maven site into source/maven on main"
if ! git config remote.asf.url > /dev/null; then
git remote add asf https://gitbox.apache.org/repos/asf/struts-site.git
fi
git fetch asf
# Check out asf/main explicitly: the Pipeline SCM checkout also leaves an
# origin/main, so a bare `git checkout main` is ambiguous across two remotes.
git checkout -B main asf/main
# The struts reactor stages module sites nested by POM inheritance, e.g.
# struts2-bom/struts2-parent/struts2-core/. Publish only what the website
# menu links to: the top-level aggregate site at the root, plus struts2-core
# and struts2-plugins flattened to /maven/<module>/. Each module site is
# self-contained (own css/js/images) and struts2-plugins carries its own
# submodule sites, so moving whole directories keeps their links intact.
STAGING=target/struts/target/staging
PARENT="${STAGING}/struts2-bom/struts2-parent"
rm -rf source/maven
mkdir -p source/maven
# Top-level aggregate site (index.html, project-info.html, aggregate apidocs,
# dependency reports), skipping the deeply-nested reactor tree.
for entry in "${STAGING}"/*; do
[ "$(basename "${entry}")" = "struts2-bom" ] && continue
cp -r "${entry}" source/maven/
done
# Flatten the two module sites the website menu references.
cp -r "${PARENT}/struts2-core" source/maven/struts2-core
cp -r "${PARENT}/struts2-plugins" source/maven/struts2-plugins
git add source/maven
git status
git diff --cached --quiet || git commit -m "Updates Maven site by Jenkins"
git push asf main
'''
}
}
}
post {
// If this build failed, send an email to the developers.
failure {
script {
emailext(
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
from: "Mr. Jenkins <jenkins@builds.apache.org>",
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} failed",
body: """
There is a build failure in ${env.JOB_NAME}.
Build: ${env.BUILD_URL}
Logs: ${env.BUILD_URL}console
Changes: ${env.BUILD_URL}changes
--
Mr. Jenkins
Director of Continuous Integration
"""
)
}
}
// Send an email, if the last build was not successful and this one is.
fixed {
script {
emailext(
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
from: 'Mr. Jenkins <jenkins@builds.apache.org>',
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} back to normal",
body: """
The build for ${env.JOB_NAME} completed successfully and is back to normal.
Build: ${env.BUILD_URL}
Logs: ${env.BUILD_URL}console
Changes: ${env.BUILD_URL}changes
--
Mr. Jenkins
Director of Continuous Integration
"""
)
}
}
}
}