Skip to content
Snippets Groups Projects
Commit 33a84745 authored by George Joseph's avatar George Joseph
Browse files

CI: Add Asterisk Gates

Change-Id: I7e2467f9120812551238d8005deb97f965279205
parent 65b002ab
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#!/usr/bin/env bash
CIDIR=$(dirname $(readlink -fn $0))
source $CIDIR/ci.functions
......@@ -25,20 +25,46 @@ gen_mods() {
done
}
sudo mkdir -p /srv/cache/externals /srv/cache/sounds || :
sudo chown -R jenkins:users /srv/cache
[ ! -d tests/CI/output ] && mkdir tests/CI/output
sudo chown -R jenkins:users tests/CI/output
[ x"$OUTPUT_DIR" != x ] && mkdir -p "$OUTPUT_DIR" 2&> /dev/null
if [ x"$CACHE_DIR" != x ] ; then
mkdir -p "$CACHE_DIR/sounds $CACHE_DIR/externals" 2&> /dev/null
fi
if [ ${CCACHE_DISABLE:-0} -ne 1 ] ; then
if [ x"$CACHE_DIR" != x ] ; then
mkdir -p $CACHE_DIR/ccache
export CCACHE_UMASK=002
export CCACHE_DIR=$CACHE_DIR/ccache
fi
case ":${PATH:-}:" in
*:/usr/lib*/ccache:*)
echo "Enabling ccache at $CCACHE_DIR"
;;
*)
if [ -d /usr/lib64/ccache ] ; then
echo "Enabling ccache at /usr/lib64/ccache with $CCACHE_DIR"
export PATH="/usr/lib64/ccache${PATH:+:$PATH}"
elif [ -d /usr/lib/ccache ] ; then
echo "Enabling ccache at /usr/lib/ccache with $CCACHE_DIR"
export PATH="/usr/lib/ccache${PATH:+:$PATH}"
fi
;;
esac
fi
runner ccache -s
runner ulimit -a
MAKE=`which make`
printenv | sort
[ -d /usr/lib64 ] && _libdir=/usr/lib64
common_config_args="--sysconfdir=/etc --with-pjproject-bundled"
common_config_args+=" --with-sounds-cache=/srv/cache/sounds --with-externals-cache=/srv/cache/externals"
common_config_args="--prefix=/usr ${_libdir:+--libdir=${_libdir}} --sysconfdir=/etc --with-pjproject-bundled"
common_config_args+=" ${CACHE_DIR:+--with-sounds-cache=${CACHE_DIR}/sounds --with-externals-cache=${CACHE_DIR}/externals}"
common_config_args+=" --enable-dev-mode"
export WGET_EXTRA_ARGS="--quiet"
runner ./configure ${common_config_args} >tests/CI/output/configure.txt
runner ./configure ${common_config_args} > ${OUTPUT_DIR:+${OUTPUT_DIR}/}configure.txt
runner ${MAKE} menuselect.makeopts
......
[
{
"name": "ari1",
"name": "ari_a-d ",
"dir": "tests/CI/output/ari1",
"testcmd": "--test-regex=tests/rest_api/[Ca-d]"
},
{
"name": "ari2",
"name": "ari_e-z ",
"dir": "tests/CI/output/ari2",
"testcmd": "--test-regex=tests/rest_api/[e-z]"
},
{
"name": "pjsip1",
"name": "pjsip_a-f",
"dir": "tests/CI/output/pjsip1",
"testcmd": "--test-regex=tests/channels/pjsip/[a-f]"
},
{
"name": "pjsip2",
"name": "pjsip_g-r",
"dir": "tests/CI/output/pjsip2",
"testcmd": "--test-regex=tests/channels/pjsip/[g-r]"
},
{
"name": "pjsip3",
"name": "pjsip_s-z",
"dir": "tests/CI/output/pjsip3",
"testcmd": "--test-regex=tests/channels/pjsip/[s-z]"
},
{
"name": "sip1",
"name": "sip_a-r ",
"dir": "tests/CI/output/sip1",
"testcmd": "--test-regex=tests/channels/SIP/[Sa-r]"
},
{
"name": "sip2",
"name": "sip_s-z ",
"dir": "tests/CI/output/sip2",
"testcmd": "--test-regex=tests/channels/SIP/[s-z]"
},
{
"name": "iax2_local",
"name": "iax2_locl",
"dir": "tests/CI/output/iax2_local",
"testcmd": " -t tests/channels/iax2 -t tests/channels/local"
},
{
"name": "extmwi",
"name": "pjsip_mwi",
"dir": "tests/CI/output/extmwi",
"testcmd": "--test-regex=tests/channels/pjsip/.*mwi"
}
......
......@@ -42,14 +42,12 @@ pipeline {
onUnstable: false
]
}
options {
skipDefaultCheckout true
}
agent {
/* All of the stages need to be performed on a docker host */
label "swdev-docker"
}
stages {
stage ("->") {
/*
......@@ -65,8 +63,16 @@ pipeline {
script {
stage ("Checkout") {
sh "sudo chown -R jenkins:users ."
env.GERRIT_PROJECT_URL = env.GERRIT_CHANGE_URL.replaceAll(/\/[0-9]+$/, "/${env.GERRIT_PROJECT}")
sh "printenv | sort"
/*
* Jenkins has already automatically checked out the base branch
* for this change but we now need to check out the change itself
* and rebase it on the current base branch. If the rebase fails,
* that's an indication to the user that they'll need to sort their
* change out.
*
* The Gerrit Trigger provides all the URLs and refspecs to
* check out the change.
*/
......@@ -81,7 +87,6 @@ pipeline {
[$class: 'CloneOption',
noTags: true,
depth: 10,
honorRefspec: true,
shallow: true
],
[$class: 'BuildChooserSetting',
......@@ -89,24 +94,32 @@ pipeline {
]
],
userRemoteConfigs: [
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GIT_URL ]
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
]
]
sh "sudo tests/CI/setupJenkinsEnvironment.sh"
}
def images = env.DOCKER_IMAGES.split(' ')
def r = currentBuild.startTimeInMillis % images.length
def ri = images[(int)r]
def randomImage = env.DOCKER_REGISTRY + "/" + ri
def dockerOptions = "-v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw --entrypoint=''"
def dockerOptions = "--ulimit core=0 --ulimit nofile=10240 " +
" -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " +
" --entrypoint=''"
def outputdir = "tests/CI/output/Testsuite"
def img = docker.image(randomImage)
img.pull()
stage ("Build") {
docker.image(randomImage).inside(dockerOptions + " --name ${BUILD_TAG}-build") {
img.inside(dockerOptions + " --name ${BUILD_TAG}-build") {
echo 'Building..'
sh './tests/CI/buildAsterisk.sh'
env.CCACHE_DIR = "/srv/cache/ccache"
sh "./tests/CI/buildAsterisk.sh --output-dir=${outputdir} --cache-dir=/srv/cache"
archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,
artifacts: "tests/CI/output/*"
artifacts: "${outputdir}/*"
}
}
......@@ -114,22 +127,23 @@ pipeline {
def parallelTasks = [ : ]
for (def testGroup in testGroups) {
parallelTasks[testGroup.name] = {
/*
* Because each task is a Groovy closure, we need to
* keep local references to some variables.
*/
def groupName = testGroup.name
def groupDir = testGroup.dir
def groupTestcmd = testGroup.testcmd
def testsuiteUrl = env.GIT_URL.replaceAll(/${GERRIT_PROJECT}$/, "testsuite")
/*
* Because each task is a Groovy closure, we need to
* keep local references to some variables.
*/
def groupName = testGroup.name
def groupDir = testGroup.dir
def groupTestcmd = testGroup.testcmd
def testsuiteUrl = env.GERRIT_PROJECT_URL.replaceAll(/${GERRIT_PROJECT}$/, "testsuite")
parallelTasks[groupName] = {
stage (groupName) {
docker.image(randomImage).inside("${dockerOptions} --name ${BUILD_TAG}-${groupName}") {
img.inside("${dockerOptions} --name ${BUILD_TAG}-${groupName}") {
sh "printenv | sort"
lock("${JOB_NAME}.${NODE_NAME}.installer") {
sh 'sudo ./tests/CI/installAsterisk.sh'
sh 'sudo ./tests/CI/installAsterisk.sh --user-group=jenkins:users'
}
sh "sudo rm -rf ${groupDir} || : "
......@@ -148,7 +162,7 @@ pipeline {
userRemoteConfigs: [[name: env.GERRIT_NAME, url: testsuiteUrl]]
]
sh "tests/CI/runTestsuite.sh --testsuite-dir='${groupDir}' --test-command='${groupTestcmd}'"
sh "sudo tests/CI/runTestsuite.sh --testsuite-dir='${groupDir}' --test-command='${groupTestcmd}'"
archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,
artifacts: "${groupDir}/asterisk-test-suite-report.xml, ${groupDir}/logs/**, ${groupDir}/core*.txt"
......@@ -156,7 +170,10 @@ pipeline {
junit testResults: "${groupDir}/asterisk-test-suite-report.xml",
healthScaleFactor: 1.0,
keepLongStdio: true
echo "Group result d: ${currentBuild.currentResult}"
}
echo "Group result s: ${currentBuild.currentResult}"
}
}
}
......@@ -166,32 +183,48 @@ pipeline {
}
}
post {
always {
sh "sudo make distclean || : "
sh "sudo rm -rf tests/CI/output || : "
cleanup {
sh "sudo make distclean 2&>/dev/null || : "
sh "sudo rm -rf tests/CI/output 2&>/dev/null || : "
}
/*
* The Gerrit Trigger will automatically post the "Verified" results back
* to Gerrit but the verification publisher publishes extra stuff in the
* "Code Review" section of the review.
*/
always {
script {
def cat
def comment
switch (currentBuild.currentResult) {
case ~/^SUCCESS$/:
cat = "Passed"
comment = ""
break
case ~/^FAILURE$/:
cat = "Failed"
comment = "Fatal Error"
break
case ~/^UNSTABLE$/:
cat = "Failed"
comment = "Tests Failed"
break
}
gerritverificationpublisher verifyStatusCategory: cat,
verifyStatusURL: '', verifyStatusComment: comment,
verifyStatusName: '', verifyStatusReporter: 'Jenkins2',
verifyStatusRerun: 'regate'
}
}
success {
gerritverificationpublisher verifyStatusCategory: 'Passed',
verifyStatusURL: '', verifyStatusComment: 'OK',
verifyStatusName: 'Jenkins2', verifyStatusReporter: '',
verifyStatusRerun: 'regate'
echo "Reporting ${currentBuild.currentResult} Passed"
}
failure {
gerritverificationpublisher verifyStatusCategory: 'Failed',
verifyStatusURL: '', verifyStatusComment: 'You\'re really screwed',
verifyStatusName: 'Jenkins2', verifyStatusReporter: '',
verifyStatusRerun: 'regate'
echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"
}
unstable {
gerritverificationpublisher verifyStatusCategory: 'Failed',
verifyStatusURL: '', verifyStatusComment: 'You\'re screwed',
verifyStatusName: 'Jenkins2', verifyStatusReporter: '',
verifyStatusRerun: 'regate'
echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"
}
}
}
#!/bin/bash
#!/usr/bin/env bash
CIDIR=$(dirname $(readlink -fn $0))
source $CIDIR/ci.functions
MAKE=`which make`
if [ x"${@}" != x ] ; then
mkdir -p "${@}"
if [ x"$DESTDIR" != x ] ; then
mkdir -p "$DESTDIR"
fi
destdir=${@:+DESTDIR=${@}}
destdir=${DESTDIR:+DESTDIR=$DESTDIR}
${MAKE} ${destdir} install || ${MAKE} ${destdir} NOISY_BUILD=yes install || exit 1
${MAKE} ${destdir} samples
if [ -n "${@}" ] ; then
sed -i -r -e "s@\[directories\]\(!\)@[directories]@g" $@/etc/asterisk/asterisk.conf
sed -i -r -e "s@ /(var|etc|usr)/@ ${@}/\1/@g" $@/etc/asterisk/asterisk.conf
if [ x"$DESTDIR" != x ] ; then
sed -i -r -e "s@\[directories\]\(!\)@[directories]@g" $DESTDIR/etc/asterisk/asterisk.conf
sed -i -r -e "s@ /(var|etc|usr)/@ $DESTDIR/\1/@g" $DESTDIR/etc/asterisk/asterisk.conf
fi
set +e
chown -R jenkins:users ${@}/var/lib/asterisk
chown -R jenkins:users ${@}/var/spool/asterisk
chown -R jenkins:users ${@}/var/log/asterisk
chown -R jenkins:users ${@}/var/run/asterisk
chown -R jenkins:users ${@}/etc/asterisk
[ ! -d ${@}/tmp/asterisk-jenkins ] && mkdir ${@}/tmp/asterisk-jenkins
chown -R jenkins:users ${@}/tmp/asterisk-jenkins
ldconfig
\ No newline at end of file
if [ x"$USER_GROUP" != x ] ; then
chown -R $USER_GROUP $DESTDIR/var/lib/asterisk
chown -R $USER_GROUP $DESTDIR/var/spool/asterisk
chown -R $USER_GROUP $DESTDIR/var/log/asterisk
chown -R $USER_GROUP $DESTDIR/var/run/asterisk
chown -R $USER_GROUP $DESTDIR/etc/asterisk
fi
ldconfig
......@@ -5,18 +5,13 @@ ASTETCDIR=$DESTDIR/etc/asterisk
pushd $TESTSUITE_DIR
sudo ./cleanup-test-temnants.sh
sudo chown -R jenkins:users .
runner sudo PYTHONPATH=./lib/python/ ./runtests.py --cleanup ${TEST_COMMAND} || :
if [ -f asterisk-test-suite-report.xml ] ; then
sudo chown jenkins:users asterisk-test-suite-report.xml
fi
./cleanup-test-remnants.sh
export PYTHONPATH=./lib/python/
runner ./runtests.py --cleanup ${TEST_COMMAND} | contrib/scripts/pretty_print --no-color --no-timer --term-width=120 --show-errors || :
if [ -f core* ] ; then
echo "*** Found a core file after running unit tests ***"
sudo /var/lib/asterisk/scripts/ast_coredumper --no-default-search core*
/var/lib/asterisk/scripts/ast_coredumper --no-default-search core*
exit 1
fi
......
......@@ -46,11 +46,11 @@ OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/}
OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml}
[ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR
sudo chown -R jenkins:users $OUTPUTDIR
[ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
rm -rf $ASTETCDIR/extensions.{ael,lua} || :
runner sudo $ASTERISK -U jenkins -G users -gn -C $CONFFILE
runner sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -gn -C $CONFFILE
sleep 3
runner $ASTERISK -rx "core waitfullybooted" -C $CONFFILE
sleep 1
......@@ -61,7 +61,7 @@ runner $ASTERISK -rx "core stop now" -C $CONFFILE
runner rsync -vaH $DESTDIR/var/log/asterisk/. $OUTPUTDIR
sudo chown -R jenkins:users $OUTPUTDIR
[ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
if [ -f core* ] ; then
echo "*** Found a core file after running unit tests ***"
$DESTDIR/var/lib/asterisk/scripts/ast_coredumper --no-default-search core*
......
#!/usr/bin/env bash
chmod 0750 /etc/sudoers.d
chmod 0440 /etc/sudoers.d/jenkins
chown root:root -R /root
chmod -R go-rwx /root/.ssh
chown -R jenkins:jenkins /home/jenkins
chown -R jenkins:jenkins /srv/cache
chown -R jenkins:jenkins /srv/jenkins
chown -R jenkins:jenkins /srv/git
chmod -R go-rwx /home/jenkins/.ssh
chmod -R go-rwx /home/jenkins/.ssh/authorized_keys
#!/usr/bin/env bash
mkdir -p /srv/cache/externals /srv/cache/sounds /srv/cache/ccache || :
chown -R jenkins:users /srv/cache
chmod g+rw /srv/cache/ccache
chmod g+s /srv/cache/ccache
mkdir -p tests/CI/output || :
chown -R jenkins:users tests/CI/output
......@@ -20,8 +20,6 @@ pipeline {
gerrit customUrl: '',
commentTextParameterMode: 'PLAIN',
commitMessageParameterMode: 'PLAIN',
gerritBuildStartedVerifiedValue: 0,
gerritBuildNotBuiltVerifiedValue: 0,
gerritBuildSuccessfulVerifiedValue: 1,
gerritBuildFailedVerifiedValue: -1,
gerritBuildUnstableVerifiedValue: -1,
......@@ -53,7 +51,7 @@ pipeline {
}
stages {
stage ("Unit Tests-->") {
stage ("->") {
/*
* Jenkins will try to automatically rebuild this job when
* the jenkinsfile changes but since this job is dependent on
......@@ -65,7 +63,10 @@ pipeline {
steps {
script {
stage ("Checkout") {
sh "sudo chown -R jenkins:users ."
sh "sudo chown -R jenkins:users ."
env.GERRIT_PROJECT_URL = env.GERRIT_CHANGE_URL.replaceAll(/\/[0-9]+$/, "/${env.GERRIT_PROJECT}")
sh "printenv | sort"
/*
* Jenkins has already automatically checked out the base branch
* for this change but we now need to check out the change itself
......@@ -76,7 +77,6 @@ pipeline {
* The Gerrit Trigger provides all the URLs and refspecs to
* check out the change.
*/
sh "sudo chown -R jenkins:users ."
checkout scm: [$class: 'GitSCM',
branches: [[name: env.GERRIT_BRANCH ]],
extensions: [
......@@ -88,7 +88,6 @@ pipeline {
[$class: 'CloneOption',
noTags: true,
depth: 10,
honorRefspec: true,
shallow: true
],
[$class: 'BuildChooserSetting',
......@@ -96,37 +95,44 @@ pipeline {
]
],
userRemoteConfigs: [
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GIT_URL ]
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
]
]
sh "sudo tests/CI/setupJenkinsEnvironment.sh"
}
def images = env.DOCKER_IMAGES.split(' ')
def r = currentBuild.startTimeInMillis % images.length
def ri = images[(int)r]
def randomImage = env.DOCKER_REGISTRY + "/" + ri;
def dockerOptions =
"-v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw" +
" --entrypoint='' --name ${BUILD_TAG}-build"
def dockerOptions = "--ulimit core=0 --ulimit nofile=10240 " +
" -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " +
" --entrypoint='' --name ${BUILD_TAG}-build"
def outputdir = "tests/CI/output/UnitTests"
docker.image(randomImage).inside(dockerOptions) {
def img = docker.image(randomImage)
img.pull()
img.inside(dockerOptions) {
stage ('Build') {
echo 'Building..'
sh './tests/CI/buildAsterisk.sh'
sh "./tests/CI/buildAsterisk.sh --output-dir=${outputdir} --cache-dir=/srv/cache"
archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,
artifacts: "tests/CI/output/*"
artifacts: "${outputdir}/*"
}
stage ('Test') {
def outputdir = "tests/CI/output/UnitTests"
def outputfile = "${outputdir}/unittests-results.xml"
def testcmd = "test execute all"
sh 'sudo ./tests/CI/installAsterisk.sh'
echo "tests/CI/runUnittests.sh --output-dir='${outputdir}' --output-xml='${outputfile}' --test-command='${testcmd}'"
sh "tests/CI/runUnittests.sh --output-dir='${outputdir}' --output-xml='${outputfile}' --test-command='${testcmd}'"
sh 'sudo ./tests/CI/installAsterisk.sh --user-group=jenkins:users'
sh "tests/CI/runUnittests.sh --user-group=jenkins:users --output-dir='${outputdir}' --output-xml='${outputfile}' --test-command='${testcmd}'"
archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,
artifacts: "${outputdir}/**"
......@@ -142,8 +148,8 @@ pipeline {
}
post {
always {
sh "sudo make distclean || : "
sh "sudo rm -rf tests/CI/output || : "
sh "sudo make distclean 2&>/dev/null || : "
sh "sudo rm -rf tests/CI/output 2&>/dev/null || : "
}
/*
* The Gerrit Trigger will automatically post the "Verified" results back
......@@ -151,21 +157,24 @@ pipeline {
* "Code Review" section of the review.
*/
success {
gerritverificationpublisher verifyStatusValue: 1, verifyStatusCategory: 'Passed',
echo "Reporting Passed"
gerritverificationpublisher verifyStatusCategory: 'Passed',
verifyStatusURL: '', verifyStatusComment: '',
verifyStatusName: '', verifyStatusReporter: '',
verifyStatusName: '', verifyStatusReporter: 'Jenkins2',
verifyStatusRerun: 'recheck'
}
failure {
gerritverificationpublisher verifyStatusValue: -1, verifyStatusCategory: 'Failed',
verifyStatusURL: '', verifyStatusComment: '',
verifyStatusName: '', verifyStatusReporter: '',
echo "Reporting Failed: Fatal Error"
gerritverificationpublisher verifyStatusCategory: 'Failed',
verifyStatusURL: '', verifyStatusComment: 'Fatal Error',
verifyStatusName: '', verifyStatusReporter: 'Jenkins2',
verifyStatusRerun: 'recheck'
}
unstable {
gerritverificationpublisher verifyStatusValue: -1, verifyStatusCategory: 'Failed',
verifyStatusURL: '', verifyStatusComment: '',
verifyStatusName: '', verifyStatusReporter: '',
echo "Reporting Failed: Tests Failed"
gerritverificationpublisher verifyStatusCategory: 'Failed',
verifyStatusURL: '', verifyStatusComment: 'Tests Failed',
verifyStatusName: '', verifyStatusReporter: 'Jenkins2',
verifyStatusRerun: 'recheck'
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment