-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrunjenkins.lua
77 lines (73 loc) · 2.81 KB
/
runjenkins.lua
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
require "pl"
function extractValue(packagestring, key)
local matchsequence = "'"..key.."':%s?'+([%w%-_%/:%.%%]+)'+,"
local valueit = string.gmatch(packagestring,matchsequence)
local thismatch = nil
for match in valueit do
thismatch = match
break
end
return thismatch
end
function extractBuildCmd(packagestring)
local startit = string.gmatch(packagestring, "'buildCmd':[%s%c]?'+(.+)")
for match in startit do
local endpos = match:find("'+]")
local substr = match:sub(0, endpos-1)
-- fix any escape sequences
substr = substr:gsub("\\","")
return substr
end
end
jenkinsfile = file.read("Jenkinsfile")
pkgListStart = jenkinsfile:find("def pkgList = %[")
endPkgList = stringx.rfind(jenkinsfile, "]")
pkgList = jenkinsfile:sub(pkgListStart,endPkgList)
print(pkgList)
curidx = 0
hasnextpackage = pkgList:find("%[",curidx)
packages = {}
while hasnextpackage do
thispkgend = pkgList:find("],", hasnextpackage+1)
thispkg = pkgList:sub(hasnextpackage,thispkgend)
print(thispkg)
hasnextpackage = pkgList:find("%[",thispkgend)
packagename = extractValue(thispkg,"name")
local scmurl = extractValue(thispkg,"scmUrl")
local scmcommit = extractValue(thispkg,"scmCommit")
local package_clone_success = false
if (scmurl ~= nil) and (scmcommit ~= nil) then
print(string.format("[%s] Need to clone %s commit %s", packagename, scmurl, scmcommit))
if (scmcommit:find("^%x+") ~= nil) then
package_clone_success = utils.execute("git clone " .. scmurl .. " " .. packagename .. " && cd " .. packagename .. " && git reset --hard " .. scmcommit)
else
local git_clone_command = "git clone --depth=1 --branch='" .. scmcommit .. "' " .. scmurl .. " " .. packagename
print(git_clone_command)
package_clone_success = utils.execute(git_clone_command)
end
else
print("scmurl or commit nil, check this: " .. tostring(scmurl) .. " commit=" .. tostring(scmcommit))
dir.makepath(packagename)
package_clone_success = true
end
if (package_clone_success) then
local buildcmd = "yes | mk-build-deps --install --remove\n" .. extractBuildCmd(thispkg)
utils.writefile(packagename .. "/jenkins_build_cmd.sh",buildcmd)
packages[#packages+1] = packagename
else
print("WARNING: package " .. packagename .. " did not clone successfully")
end
end
for i,packagename in ipairs(packages) do
print("Doing compile for " .. packagename)
local package_build_success,package_build_ret,package_build_stdout,package_build_stderr = utils.executeex("cd " .. packagename .. " && sh jenkins_build_cmd.sh 2>&1")
if (package_build_success ~= true) then
print("Error: " .. packagename .. " did not build successfully")
print("Return code: " .. tostring(package_build_ret))
print("stdout: ")
print(package_build_stdout)
print("------------------------------------------------------")
os.exit(1)
end
print("Compile task for " .. packagename .. " done")
end