-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
139 lines (125 loc) · 5.04 KB
/
Jenkinsfile
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
/**
* <p>
* This is the script that will be run by Jenkins to build and test this
* project. This drives the project's continuous integration and delivery.
* </p>
* <p>
* This script is run by Jenkins' Pipeline feature. A good intro tutorial for
* working with Jenkins Pipelines can be found here:
* <a href="https://jenkins.io/doc/book/pipeline/">Jenkins > Pipeline</a>.
* </p>
* <p>
* The canonical Jenkins server job for this project is located here:
* <a href="https://justdavis.com/jenkins/job/rps-tourney/">rps-tourney</a>.
* </p>
*/
properties([
disableConcurrentBuilds(),
parameters([
/*
* Benchmarks aren't run by default as they're only valid when the
* build server isn't busy with anything else.
*/
booleanParam(name: 'tests_skip', description: 'Whether to skip unit and integration tests.', defaultValue: false),
booleanParam(name: 'deploy_non_master', description: 'Whether to deploy non-master-branch builds to production.', defaultValue: false),
booleanParam(name: 'benchmarks_run', description: 'The app benchmarks will be run if this is set to true.', defaultValue: false),
string(name: 'benchmarks_forks', description: 'How many forks to run of each benchmark.', defaultValue: '10'),
string(name: 'benchmarks_iterations', description: 'How many measurement iterations to run of each benchmark (per fork).', defaultValue: '20')
])
])
node {
stage('Checkout') {
// Grab the commit that triggered the build.
checkout scm
}
stage('Build') {
/*
* Only `master` branch builds should be installed to the local Maven
* repo or deployed to the Nexus repo.
*/
def goal = env.BRANCH_NAME == "master" ? "deploy" : "verify"
// Run the build. Make sure to archive build results even if it fails.
try {
mvn "--update-snapshots -DskipTests=${params.tests_skip} -DskipITs=${params.tests_skip} clean ${goal}"
} finally {
/*
* Fingerprint the output artifacts and archive the test results.
* (Archiving the output artifacts here would waste space, as the
* build deploys them to the local Maven repository.)
*/
fingerprint '**/target/*.jar'
fingerprint '**/target/*.war'
junit testResults: '**/target/*-reports/TEST-*.xml', keepLongStdio: true, allowEmptyResults: true
archiveArtifacts artifacts: '**/target/*-reports/*.txt', allowEmptyArchive: true
}
}
stage('Benchmark') {
if (params.benchmarks_run) {
dir('rps-tourney-benchmarks') {
java "-jar target/benchmarks.jar -foe true -rf json -rff target/jmh-result.json -f ${benchmarks_forks} -i ${benchmarks_iterations}"
archiveArtifacts artifacts: 'target/jmh-result.json', allowEmptyArchive: true
}
}
}
stage('Quality Analysis') {
/*
* The 'justdavis-sonarqube' SonarQube server will be sent the analysis
* results. See
* https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins
* for details. Note that the free version of SonarQube we're using
* doesn't separate results by branch.
*/
withSonarQubeEnv('justdavis-sonarqube') {
mvn "org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar"
}
}
stage('Deployment') {
if (params.deploy_non_master || (env.BRANCH_NAME == 'master')) {
dir('rps-tourney-deployment') {
withPythonEnv('/usr/bin/python2.7') {
pysh "pip install --upgrade setuptools"
pysh "pip install --requirement requirements.txt"
pysh "ansible-galaxy install --role-file=install_roles.yml --force"
withCredentials([file(credentialsId: 'rps-tourney-ansible-vault-password', variable: 'vaultPasswordFile')]) {
sshagent(['eddings-builds-ssh-private-key']) {
// Configure the Ansible Vault password file.
vaultPasswordFileEscaped = vaultPasswordFile.replaceAll("/", "\\\\/")
sh "sed --in-place 's/^vault_password_file = .*\$/vault_password_file = ${vaultPasswordFileEscaped}/g' ansible.cfg"
// Mark edding's SSH host key as known if it isn't already.
sh "grep --quiet 'eddings.justdavis.com' ~/.ssh/known_hosts || ssh-keyscan -t rsa eddings.justdavis.com 2>/dev/null >> ~/.ssh/known_hosts"
// Check the Ansible play then run it.
pysh "./ansible-playbook-wrapper site.yml --syntax-check"
pysh "./ansible-playbook-wrapper site.yml"
} }
} }
}
}
}
/**
* Runs Maven with the specified arguments.
*
* @param args the arguments to pass to <code>mvn</code>
*/
def mvn(args) {
// This tool must be setup and named correctly in the Jenkins config.
def mvnHome = tool 'maven-3'
// Run the build, using Maven, with the appropriate config.
configFileProvider(
[
configFile(fileId: 'justdavis:settings.xml', variable: 'MAVEN_SETTINGS'),
configFile(fileId: 'justdavis:toolchains.xml', variable: 'MAVEN_TOOLCHAINS')
]
) {
sh "${mvnHome}/bin/mvn --settings $MAVEN_SETTINGS --toolchains $MAVEN_TOOLCHAINS ${args}"
}
}
/**
* Runs Java with the specified arguments.
*
* @param args the arguments to pass to <code>java</code>
*/
def java(args) {
// This tool must be setup and named correctly in the Jenkins config.
def jdkHome = tool type: 'jdk', name: 'openjdk-8-jdk'
sh "${jdkHome}/bin/java ${args}"
}