Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 78 lines (61 sloc) 2.751 kb
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

run_trigger() {

GitDevBranchName="master"
if [[ "$dirname" =~ /jobs/.*/workspace$ ]]
then
JobName="$(echo $dirname | sed 's/^.*\/jobs\/\([^/]\+\)\/workspace$/\1/')"
# Query job status
JobInQueue="$(curl -s http://$jenkins/job/$JobName/api/json | perl -MJSON::XS -e "\$a='';while(<>){\$a.=\$_} \$d=decode_json(\$a);print \$d->{'inQueue'}")"
if [[ "$JobInQueue" == 1 ]];
then
# Job sits in queue, exiting
exit 0
fi
LastBuildFailed=$(curl -s http://$jenkins/job/$JobName/api/json | perl -MJSON::XS -e "\$a='';while(<>){\$a.=\$_} \$d=decode_json(\$a);print \$d->{'lastBuild'}{'number'} == \$d->{'lastUnsuccessfulBuild'}{'number'} ? 1 : 0")
if [[ "$LastBuildFailed" == 1 ]];
then
# Last job failed, user intervention required
# Usually that happens when upstream changed
# something that breaks our build/patches, etc.
exit 0
fi
else
echo "This script is designed to run from within Jenkins workspace"
exit -1
fi

# We are not going to build by default
FireNewBuild=0

# Obtaining current branch name from our local git repo
GitCurBranch="$(git branch|grep '*'|cut -f2 -d' ')"

# Getting git revisions of specfile for comparition:
# remote:
GitRev="$(curl -s http://github.com/api/v2/json/commits/list/$GithubUserProject/$GitCurBranch/$SpecOrig | perl -MJSON::XS -e "\$a='';while(<>){\$a.=\$_} \$d=decode_json(\$a);print \$d->{'commits'}[0]->{'id'}")"
# local:
OurRev=$(git log --pretty=format:"%H" -1 $SpecOrig)

if [[ "$GitRev" != "$OurRev" ]]; then
# Git revision was updated in upstream repository, need to build it
FireNewBuild=1
fi



if [[ "$GitCurBranch" == "$GitDevBranchName" ]]; then
CurTarballVer=(`curl -s $TarballsHome/?C=M\;O=D | grep -m 1 'nova-[0-9]' | perl -p -e 's!^.*nova-(\d+\.\d+)~(\w+)~(\d+\.\d+)\.tar\.gz.*$!\n$1 $2 $3 $4 $5\n!i'`)

# We are on development version (trunk)
# That means that we need also to consider
# upstream tarballs as trigger for build
#SpecVer=$(grep '^Version:' $SpecOrig | sed 's/^Version:\s\+//')
#SpecRelease=$(grep '^Release:' $SpecOrig | sed 's/^Release:\s\+//' | sed 's/%{?dist}$//')

#Build="$(curl -s $TarballsHome'/?C=M;O=D' | grep $SpecVer | grep bzr | perl -pi -e 's/^.*bzr(\d+).*$/$1/' | head -n 1)"
#OurBuild=$(echo "$SpecRelease" | cut -d. -f3 | sed 's/bzr//')

NewRelease=${CurTarballVer[2]}
OldRelease=$(grep '^Release:' $SpecOrig | sed 's/^Release:\s\+//' | sed 's/%{?dist}$//')


echo "OldRelease = $OldRelease"
echo "NewRelease = $NewRelease"


if [[ "$OldRelease" != 0."$NewRelease" ]]; then
# We are behind trunk - need to fire a new build
FireNewBuild=1
fi
fi

if [[ "$FireNewBuild" == 1 ]];
then
curl -s "http://$jenkins/job/$JobName/build"
echo "Fire jenkins!"
fi
}
Something went wrong with that request. Please try again.