forked from metasfresh/metasfresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
137 lines (122 loc) · 5.57 KB
/
Copy pathJenkinsfile
File metadata and controls
137 lines (122 loc) · 5.57 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
#!/usr/bin/env groovy
// the "!#/usr/bin... is just to to help IDEs, GitHub diffs, etc properly detect the language and do syntax highlighting for you.
// thx to https://github.com/jenkinsci/pipeline-examples/blob/master/docs/BEST_PRACTICES.md
// note that we set a default version for this library in jenkins, so we don't have to specify it here
@Library('misc')
import de.metas.jenkins.DockerConf
import de.metas.jenkins.Misc
import de.metas.jenkins.MvnConf
chuckNorris()
// keep the last 20 builds for master and stable, but onkly the last 10 for the rest, to preserve disk space on jenkins
final String numberOfBuildsToKeepStr = (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'stable') ? '20' : '10'
final String MF_SQL_SEED_DUMP_URL_DEFAULT =
env.BRANCH_NAME == 'release'
? 'https://metasfresh.com/wp-content/releases/db_seeds/metasfresh-5_39.pgdump'
: 'https://metasfresh.com/wp-content/releases/db_seeds/metasfresh_latest.pgdump'
// thx to http://stackoverflow.com/a/36949007/1012103 with respect to the parameters
properties([
parameters([
booleanParam(defaultValue: false,
description: 'If true, then rebuild everything, no matter if there were changes',
name: 'MF_FORCE_FULL_BUILD'),
string(defaultValue: MF_SQL_SEED_DUMP_URL_DEFAULT,
description: 'metasfresh database seed against which the build shall apply its migrate scripts for QA; leave empty to avoid this QA.',
name: 'MF_SQL_SEED_DUMP_URL'),
]),
pipelineTriggers([]),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: numberOfBuildsToKeepStr)) // keep the last $numberOfBuildsToKeepStr builds
]);
currentBuild.description = currentBuild.description ?: '';
try
{
timestamps
{
// https://github.com/metasfresh/metasfresh/issues/2110 make version/build infos more transparent
final String MF_VERSION=retrieveArtifactVersion(env.BRANCH_NAME, env.BUILD_NUMBER)
currentBuild.displayName="artifact-version ${MF_VERSION}";
node('agent && linux')
{
configFileProvider([configFile(fileId: 'metasfresh-global-maven-settings', replaceTokens: true, variable: 'MAVEN_SETTINGS')])
{
// create our config instance to be used further on
final MvnConf mvnConf = new MvnConf(
'pom.xml', // pomFile
MAVEN_SETTINGS, // settingsFile
"mvn-${env.BRANCH_NAME}".replace("/", "-"), // mvnRepoName
'https://repo.metasfresh.com' // mvnRepoBaseURL
)
echo "mvnConf=${mvnConf.toString()}"
final def scmVars = checkout scm
echo "git debug scmVars=>>>>>${scmVars}<<<<<"
currentBuild.description = """${currentBuild.description}
<b>
<ul>
<li>This job builds commit <a href="https://github.com/metasfresh/metasfresh/commit/${scmVars.GIT_COMMIT}">${scmVars.GIT_COMMIT}</a></li>
<li>The changes since the last successful commit are <a href="https://github.com/metasfresh/metasfresh/compare/${scmVars.GIT_PREVIOUS_SUCCESSFUL_COMMIT}..${scmVars.GIT_COMMIT}">here</a></li>
</ul>
</b>
"""
sh 'git clean -d --force -x' // clean the workspace
// we need to provide MF_VERSION because otherwise the profile "MF_VERSION-env-missing" would be activated from the metasfresh-parent pom.xml
// and therefore, the jenkins information would not be added to the build.properties info file.
withEnv(["MF_VERSION=${MF_VERSION}"])
{
// disable automatic fingerprinting and archiving by artifactsPublisher, because in particular the archiving takes up too much space on the jenkins server.
withMaven(jdk: 'java-8', maven: 'maven-3.6.3', mavenLocalRepo: '.repository', mavenOpts: '-Xmx1536M', options: [artifactsPublisher(disabled: true)])
{
nexusCreateRepoIfNotExists(mvnConf.mvnDeployRepoBaseURL, mvnConf.mvnRepoName)
dir('misc/parent-pom')
{
def parentPom = load('buildfile.groovy')
parentPom.build(mvnConf, scmVars) // in there we don't do diff..we always build&deploy it.
}
// note: to do some of this in parallel, we first need to make sure that the different parts don't concurrently write to the build description
dir('frontend')
{
def frontendBuildFile = load('buildfile.groovy')
frontendBuildFile.build(mvnConf, scmVars, params.MF_FORCE_FULL_BUILD)
}
dir('backend')
{
def backendBuildFile = load('buildfile.groovy')
backendBuildFile.build(mvnConf, scmVars, params.MF_FORCE_FULL_BUILD)
}
dir('misc/services')
{
def miscServices = load('buildfile.groovy')
miscServices.build(mvnConf, scmVars, params.MF_FORCE_FULL_BUILD)
}
dir('e2e')
{
def e2eBuildFile = load('buildfile.groovy')
e2eBuildFile.build(scmVars, params.MF_FORCE_FULL_BUILD)
}
dir('distribution')
{
def distributionBuildFile = load('buildfile.groovy')
distributionBuildFile.build(mvnConf);
}
//junit '**/target/surefire-reports/*.xml'
publishJacocoReports(scmVars.GIT_COMMIT, 'codacy_project_token_for_metasfresh_repo')
} // withMaven
} // withEnv
} // configFileProvider
cleanWs cleanWhenAborted: false, cleanWhenFailure: false // clean up the workspace after (successfull) builds
} // node
} // timestamps
} catch(all)
{
final String mattermostMsg = "This **${env.BRANCH_NAME}** build failed or was aborted: ${BUILD_URL}"
if(env.BRANCH_NAME=='master' || env.BRANCH_NAME=='release')
{
mattermostSend color: 'danger', message: mattermostMsg
}
else
{
withCredentials([string(credentialsId: 'jenkins-issue-branches-webhook-URL', variable: 'secretWebhookUrl')])
{
mattermostSend color: 'danger', endpoint: secretWebhookUrl, channel: 'jenkins-low-prio', message: mattermostMsg
}
}
throw all
}