-
Notifications
You must be signed in to change notification settings - Fork 21
/
Jenkinsfile
116 lines (106 loc) · 4.39 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
def projectName = "solid_dmft" /* set to app/repo name */
def dockerName = projectName.toLowerCase();
/* which platform to build documentation on */
def documentationPlatform = "ubuntu-clang"
/* depend on triqs upstream branch/project */
def triqsBranch = env.CHANGE_TARGET ?: env.BRANCH_NAME
def triqsProject = '/TRIQS/triqs/' + triqsBranch.replaceAll('/', '%2F')
def cthybProject = '/TRIQS/cthyb/' + triqsBranch.replaceAll('/', '%2F')
/* whether to keep and publish the results */
def keepInstall = !env.BRANCH_NAME.startsWith("PR-")
properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '10', daysToKeepStr: '30')),
pipelineTriggers(keepInstall ? [
upstream(
threshold: 'SUCCESS',
upstreamProjects: cthybProject
)
] : [])
])
/* map of all builds to run, populated below */
def platforms = [:]
/****************** linux builds (in docker) */
/* Each platform must have a cooresponding Dockerfile.PLATFORM in triqs/packaging */
def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc"]
/* .each is currently broken in jenkins */
for (int i = 0; i < dockerPlatforms.size(); i++) {
def platform = dockerPlatforms[i]
platforms[platform] = { -> node('linux && docker && triqs') {
stage(platform) { timeout(time: 1, unit: 'HOURS') { ansiColor('xterm') {
checkout scm
/* construct a Dockerfile for this base */
sh """
( echo "FROM flatironinstitute/cthyb:${triqsBranch}-${env.STAGE_NAME}" ; sed '0,/^FROM /d' Docker/jenkins_ci_dockerfile ) > Dockerfile.jenkins
mv -f Dockerfile.jenkins Dockerfile
"""
/* build and tag */
def args = ''
if (platform == documentationPlatform)
args = '-DBuild_Documentation=0'
else if (platform == "sanitize")
args = '-DASAN=ON -DUBSAN=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo'
def img = docker.build("flatironinstitute/${dockerName}:${env.BRANCH_NAME}-${env.STAGE_NAME}", "--build-arg APPNAME=${projectName} --build-arg BUILD_ID=${env.BUILD_TAG} --build-arg CMAKE_ARGS='${args}' .")
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
img.inside("--shm-size=4gb") {
sh "make -C \$BUILD/${projectName} test CTEST_OUTPUT_ON_FAILURE=1"
}
}
if (!keepInstall) {
sh "docker rmi --no-prune ${img.imageName()}"
}
} } }
} }
}
/****************** wrap-up */
def error = null
try {
parallel platforms
if (keepInstall) { node('linux && docker && triqs') {
/* Publish results */
stage("publish") { timeout(time: 5, unit: 'MINUTES') {
def commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
def release = env.BRANCH_NAME == "master" || env.BRANCH_NAME == "unstable" || sh(returnStdout: true, script: "git describe --exact-match HEAD || true").trim()
def workDir = pwd(tmp:true)
lock('triqs_publish') {
/* Update packaging repo submodule */
if (release) { dir("$workDir/packaging") { try {
git(url: "ssh://git@github.com/TRIQS/packaging.git", branch: env.BRANCH_NAME, credentialsId: "ssh", changelog: false)
// note: credentials used above don't work (need JENKINS-28335)
sh """#!/bin/bash -ex
dir="${projectName}"
[[ -d \$dir ]] && dir=\$dir || [[ -d \$dir ]]
echo "160000 commit ${commit}\t\$dir" | git update-index --index-info
git commit --author='Flatiron Jenkins <jenkins@flatironinstitute.org>' -m 'Autoupdate ${projectName}' -m '${env.BUILD_TAG}'
git push origin ${env.BRANCH_NAME}
"""
} catch (err) {
/* Ignore, non-critical -- might not exist on this branch */
echo "Failed to update packaging repo"
} } }
}
} }
} }
} catch (err) {
error = err
} finally {
/* send email on build failure (declarative pipeline's post section would work better) */
if ((error != null || currentBuild.currentResult != 'SUCCESS') && env.BRANCH_NAME != "jenkins") emailext(
subject: "\$PROJECT_NAME - Build # \$BUILD_NUMBER - FAILED",
body: """\$PROJECT_NAME - Build # \$BUILD_NUMBER - FAILED
Check console output at \$BUILD_URL to view full results.
Building \$BRANCH_NAME for \$CAUSE
\$JOB_DESCRIPTION
Changes:
\$CHANGES
End of build log:
\${BUILD_LOG,maxLines=60}
""",
to: 'nwentzell@flatironinstitute.org',
recipientProviders: [
[$class: 'DevelopersRecipientProvider'],
],
replyTo: '$DEFAULT_REPLYTO'
)
if (error != null) throw error
}