forked from imatix/gsl
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Jenkinsfile
118 lines (118 loc) · 6.66 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
pipeline {
agent { label "linux || macosx || bsd || solaris || posix || windows" }
parameters {
// Use DEFAULT_DEPLOY_BRANCH_PATTERN and DEFAULT_DEPLOY_JOB_NAME if
// defined in this jenkins setup -- in Jenkins Management Web-GUI
// see Configure System / Global properties / Environment variables
// Default (if unset) is empty => no deployment attempt after good test
// See zproject Jenkinsfile-deploy.example for an example deploy job.
// TODO: Try to marry MultiBranchPipeline support with pre-set defaults
// directly in MultiBranchPipeline plugin, or mechanism like Credentials,
// or a config file uploaded to master for all jobs or this job, see
// https://jenkins.io/doc/pipeline/examples/#configfile-provider-plugin
string (
defaultValue: '${DEFAULT_DEPLOY_BRANCH_PATTERN}',
description: 'Regular expression of branch names for which a deploy action would be attempted after a successful build and test; leave empty to not deploy. Reasonable value is ^(master|release/.*|feature/*)$',
name : 'DEPLOY_BRANCH_PATTERN')
string (
defaultValue: '${DEFAULT_DEPLOY_JOB_NAME}',
description: 'Name of your job that handles deployments and should accept arguments: DEPLOY_GIT_URL DEPLOY_GIT_BRANCH DEPLOY_GIT_COMMIT -- and it is up to that job what to do with this knowledge (e.g. git archive + push to packaging); leave empty to not deploy',
name : 'DEPLOY_JOB_NAME')
booleanParam (
defaultValue: true,
description: 'If the deployment is done, should THIS job wait for it to complete and include its success or failure as the build result (true), or should it schedule the job and exit quickly to free up the executor (false)',
name: 'DEPLOY_REPORT_RESULT')
booleanParam (
defaultValue: true,
description: 'Attempt a "make install" check in this run?',
name: 'DO_TEST_INSTALL')
string (
defaultValue: "`pwd`/tmp/_inst",
description: 'If attempting a "make install" check in this run, what DESTDIR to specify? (absolute path, defaults to "BUILD_DIR/tmp/_inst")',
name: 'USE_TEST_INSTALL_DESTDIR')
booleanParam (
defaultValue: true,
description: 'When using temporary subdirs in build/test workspaces, wipe them after successful builds?',
name: 'DO_CLEANUP_AFTER_BUILD')
}
triggers {
pollSCM 'H/5 * * * *'
}
// Note: your Jenkins setup may benefit from similar setup on side of agents:
// PATH="/usr/lib64/ccache:/usr/lib/ccache:/usr/bin:/bin:${PATH}"
stages {
stage ('compile') {
steps {
dir ('src') {
sh 'CCACHE_BASEDIR="`pwd`" ; export CCACHE_BASEDIR; make -k -j4 || make'
sh 'echo "Are GitIgnores good after make? (should have no output below)"; git status -s || true'
}
}
}
stage ('test') {
steps {
dir ('src') {
sh 'CCACHE_BASEDIR="`pwd`" ; export CCACHE_BASEDIR; make test'
// The test is trivial (run the binary to see if it works
// and prints the version), there is no git status to validate
}
}
}
stage ('self-check GSL parser') {
steps {
dir ('src') {
sh 'CCACHE_BASEDIR="`pwd`" ; export CCACHE_BASEDIR; make check'
sh 'echo "Are GitIgnores good after make check? (should have no output below)"; git status -s || true'
}
}
}
stage ('install') {
when { expression { return ( params.DO_TEST_INSTALL ) } }
steps {
timeout (time: 5, unit: 'MINUTES') {
sh """CCACHE_BASEDIR="`pwd`" ; export CCACHE_BASEDIR; make DESTDIR="${params.USE_TEST_INSTALL_DESTDIR}" install"""
}
sh 'echo "Are GitIgnores good after make install? (should have no output below)"; git status -s || true'
script {
if ( params.DO_CLEANUP_AFTER_BUILD ) {
dir("${params.USE_TEST_INSTALL_DESTDIR}") {
deleteDir()
}
}
}
}
}
stage ('deploy if appropriate') {
steps {
script {
def myDEPLOY_JOB_NAME = sh(returnStdout: true, script: """echo "${params["DEPLOY_JOB_NAME"]}" """).trim();
def myDEPLOY_BRANCH_PATTERN = sh(returnStdout: true, script: """echo "${params["DEPLOY_BRANCH_PATTERN"]}" """).trim();
def myDEPLOY_REPORT_RESULT = sh(returnStdout: true, script: """echo "${params["DEPLOY_REPORT_RESULT"]}" """).trim().toBoolean();
echo "Original: DEPLOY_JOB_NAME : ${params["DEPLOY_JOB_NAME"]} DEPLOY_BRANCH_PATTERN : ${params["DEPLOY_BRANCH_PATTERN"]} DEPLOY_REPORT_RESULT : ${params["DEPLOY_REPORT_RESULT"]}"
echo "Used: myDEPLOY_JOB_NAME:${myDEPLOY_JOB_NAME} myDEPLOY_BRANCH_PATTERN:${myDEPLOY_BRANCH_PATTERN} myDEPLOY_REPORT_RESULT:${myDEPLOY_REPORT_RESULT}"
if ( (myDEPLOY_JOB_NAME != "") && (myDEPLOY_BRANCH_PATTERN != "") ) {
if ( env.BRANCH_NAME =~ myDEPLOY_BRANCH_PATTERN ) {
def GIT_URL = sh(returnStdout: true, script: """git remote -v | egrep '^origin' | awk '{print \$2}' | head -1""").trim()
def GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse --verify HEAD').trim()
build job: "${myDEPLOY_JOB_NAME}", parameters: [
string(name: 'DEPLOY_GIT_URL', value: "${GIT_URL}"),
string(name: 'DEPLOY_GIT_BRANCH', value: env.BRANCH_NAME),
string(name: 'DEPLOY_GIT_COMMIT', value: "${GIT_COMMIT}")
], quietPeriod: 0, wait: myDEPLOY_REPORT_RESULT, propagate: myDEPLOY_REPORT_RESULT
} else {
echo "Not deploying because branch '${env.BRANCH_NAME}' did not match filter '${myDEPLOY_BRANCH_PATTERN}'"
}
} else {
echo "Not deploying because deploy-job parameters are not set"
}
}
}
}
stage ('cleanup') {
when { expression { return ( params.DO_CLEANUP_AFTER_BUILD ) } }
steps {
deleteDir()
}
}
}
}