forked from opentext-idol/myway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
178 lines (158 loc) · 5.11 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
withEnv( [
'JENKINS_SFTP_SERVERS=/var/lib/jenkins/iod/software_servers.cfg'
, 'JENKINS_COMPONENT_CFG=src/.build/package.cfg'
, 'JENKINS_HISTORY_DIR=/var/lib/jenkins/iod/history'
, 'JENKINS_FORCE_REBUILD=1'
, 'GITLOG2DCL_PKG_NAME=dbtools'
] ) {
def nodeTag = getNode()
node( nodeTag ) {
env.WORKSPACE = pwd()
env.JENKINS_BUILD_TAG = getBranchTag()
env.JENKINS_SERVER_TAGS = getSCPTags()
stage( 'Checkout' ) {
sh 'mkdir -p src'
dir( 'src' ) {
gitClean()
checkout scm
}
sh '''
test -d util && rm -r util
git clone https://github.com/srcshelton/gitlog2dcl.git util
chmod 755 util/gitlog2dcl.sh
'''
dir( 'src' ) {
sh '''
../util/gitlog2dcl.sh 2>/dev/null > debian/changelog
echo "dbtools_$( ../util/gitlog2dcl.sh 2>/dev/null | head -n 1 | cut -d'(' -f 2 | cut -d')' -f 1 )_noarch.deb database extra" > debian/files
'''
}
}
stage( 'Build' ) {
try {
sh '''
set +e
http_proxy="${HTTP_PROXY:-}"
https_proxy="${HTTPS_PROXY:-${HTTP_PROXY:-}}"
export http_proxy https_proxy
#cpan="/usr/bin/cpanm"
cpan="/usr/bin/cpan"
for shsrc in *.sh; do
[ -r "${shsrc}" ] && if ! bash -n "${shsrc}" >/dev/null 2>&1; then
echo >&2 "bash syntax check on '${shsrc}' failed:"
bash -n "${shsrc}" >&2
exit 1
fi
done
for plsrc in *.pl; do
if [ -r "${plsrc}" ]; then
if ! [ -e ~/perl/lib/perl5/local/lib.pm ]; then
llver="2.000019"
wget "http://search.cpan.org/CPAN/authors/id/H/HA/HAARG/local-lib-${llver}.tar.gz"
tar -xzpf "local-lib-${llver}.tar.gz"
cd "local-lib-${llver}"
perl Makefile.PL --bootstrap=~/perl --no-manpages
make test
make install
cd -
fi
eval "$(perl -I${HOME}/perl/lib/perl5 -Mlocal::lib)"
case "$( basename "${cpan}" )" in
cpan)
{
echo y
echo o conf prerequisites_policy follow
echo o conf make_install_arg UNINST=0
echo o conf makepl_arg "PREFIX=~/perl LIB=~/perl/lib/perl5 INSTALLSITEMAN1DIR=~/perl/man/man1 INSTALLSITEMAN3DIR=~/perl/man/man3 INSTALLSCRIPT=~/perl/bin INSTALLBIN=~/perl/bin"
echo o conf mbuildpl_arg "--install_base ~/perl --lib=~/perl/lib/perl5 --installman1dir=~/perl/man/man1 --installman3dir=~/perl/man/man3 --installscript=~/perl/bin --installbin=~/perl/bin"
echo o conf commit
} | "${cpan}" --version || true
;;
*)
:
;;
esac
MANPATH="${MANPATH:+${MANPATH}:}~/perl/man"
export MANPATH
grep -w 'use' "${plsrc}" |
sed 's/^\\s*// ; s/#.*$//' |
grep '^use\\s' |
tr -s [:space:] |
cut -d ' ' -f 2 |
sed 's/;\\s*$//' |
sort |
uniq |
while read M
do
# Unbelievable... :(
if [ "${M}" = "match::smart" ]; then
M="match::simple"
fi
perl -M"${M}" -e 'print( "ok\\n" );' || {
echo >&2 "Invoking '${cpan}' to install Perl module '${M}' as run-time dependency of '${plsrc}' ..."
"${cpan}" -i "${M}"
}
done
if ! perl -c "${plsrc}" >/dev/null 2>&1; then
echo >&2 "perl syntax check on '${plsrc}' failed:"
perl -c "${plsrc}" >&2
exit 1
fi
fi
done
/var/lib/jenkins/iod/build-scripts/build-components.sh
'''
currentBuild.result = 'SUCCESS'
} catch( Exception err ) {
currentBuild.result = 'FAILURE'
}
}
stage( 'Notifications' ) {
echo "Please ignore 'Job type does not allow token replacement.' warnings below, which come from the email plugin..."
emailext \
to: '$DEFAULT_RECIPIENTS' \
, subject: "JENKINS - ${env.JOB_NAME} - Build #${env.BUILD_NUMBER}: ${currentBuild.result}" \
, body: "View console output at ${env.BUILD_URL}\n\n" \
, attachLog: true
}
}
}
def getNode() {
def matcher = env.BRANCH_NAME =~ '(release|develop|stable|hotfix)'
matcher ? 'persistent-builds' : 'feature-builds'
}
def getBranchTag() {
def matcher = env.BRANCH_NAME =~ '(release|feature|hotfix)/(.*)'
matcher ? matcher[0][1] + '-' + matcher[0][2] : env.BRANCH_NAME
}
def getSCPTags() {
def matcher = env.BRANCH_NAME =~ 'feature'
matcher ? 'ops-tools-dev' : 'all'
}
/**
* Clean a Git project workspace.
* Uses 'git clean' if there is a repository found.
* Uses Pipeline 'deleteDir()' function if no .git directory is found.
*/
def gitClean() {
timeout(time: 60, unit: 'SECONDS') {
if( fileExists( '.git' ) ) {
echo 'Found git repository: using git to clean the tree.'
// The sequence of reset --hard and clean -fdx first
// in the root and then using submodule foreach
// is based on how the Jenkins Git SCM clean before checkout
// feature works.
sh 'git reset --hard'
// Note: -e is necessary to exclude the temp directory
// .jenkins-XXXXX in the workspace where Pipeline puts the
// batch file for the 'bat' command.
sh 'git clean -ffdx -e ".jenkins-*/"'
sh 'git submodule foreach --recursive git reset --hard'
sh 'git submodule foreach --recursive git clean -ffdx'
} else {
echo 'No git repository found: using deleteDir() to clean workspace'
deleteDir()
}
}
}
// vi: set syntax=groovy: