testing_30

This commit is contained in:
psycho 2020-08-14 00:34:22 +02:00
parent 415a0a48d2
commit 9b1e676d9b
2 changed files with 92 additions and 36 deletions

52
Jenkinsfile vendored
View File

@ -71,6 +71,7 @@ def printDebug(msg)
node('test')
{
//currentbuild.result = 'SUCCESS'
stage('checkout')
{
if(pre_clean)
@ -86,30 +87,35 @@ node('test')
}
}
if(isBuildNeeded)
stage('pre-build')
{
stage('pre-build')
{
sh label: 'patch_sources', script: 'cd ' + git_folder + '; patch -p1 < ../' + patch
sh label: 'feeds_update', script: 'cd ' + git_folder + '; ./scripts/feeds update -a'
sh label: 'feeds_install', script: 'cd ' + git_folder + '; ./scripts/feeds install -a'
}
stage('build')
{
//step
//{
sh label: 'copy_config', script: 'cp ' + config_path + 'tl_wr841_v11_config ' + git_folder + '/.config'
sh label: 'build_v11', script: 'cd ' + git_folder + '; make oldconfig; make -j13 V=s'
//}
//step
//{
sh label: 'copy_config', script: 'cp ' + config_path + 'tl_wr841_v12_config ' + git_folder + '/.config'
sh label: 'build_v12', script: 'cd ' + git_folder + '; make oldconfig; make -j13 V=s'
//}
}
}
sh label: 'patch_sources', script: 'cd ' + git_folder + '; patch -p1 < ../' + patch
sh label: 'feeds_update', script: 'cd ' + git_folder + '; ./scripts/feeds update -a'
sh label: 'feeds_install', script: 'cd ' + git_folder + '; ./scripts/feeds install -a'
}
stage('build')
{
//step
//{
sh label: 'copy_config', script: 'cp ' + config_path + 'tl_wr841_v11_config ' + git_folder + '/.config'
sh label: 'build_v11', script: 'cd ' + git_folder + '; make oldconfig; make -j13 V=s'
//}
//step
//{
sh label: 'copy_config', script: 'cp ' + config_path + 'tl_wr841_v12_config ' + git_folder + '/.config'
sh label: 'build_v12', script: 'cd ' + git_folder + '; make oldconfig; make -j13 V=s'
//}
}
stage('move_bin_to_ftp')
{
sh label: 'copy_binaries', script: 'python ' + scripts_path + 'sftp_test.py -a ' + sftp_host + ' -u ' + sftp_user + ' -p ' + sftp_passwd + ' -g ' + git_folder + ' -f ' + scripts_path + known_hosts + ' -l ' + sftp_path + ' -c ' + git_folder + '/bin'
}
if(post_clean)
{

View File

@ -65,7 +65,7 @@ def print_version():
def parse_args():
#try parsing arguments according to defined format
try:
opts, args = getopt.getopt(sys.argv[1:], 'a:u:p:f:g:l:dvh', ['host=', 'user=', 'passwd=', 'host_file=', 'git_path=', 'sftp_path', 'debug', 'version', 'help'])
opts, args = getopt.getopt(sys.argv[1:], 'a:u:p:f:g:l:c:dvh', ['host=', 'user=', 'passwd=', 'host_file=', 'git_path=', 'sftp_path=', 'cp_path=', 'debug', 'version', 'help'])
except getopt.GetoptError:
err('',2) #parsing failed
@ -76,6 +76,7 @@ def parse_args():
sftp_path = ''
known_hosts = ''
git_path = ''
cp_path = ''
#check if arguments even present
if not opts:
@ -102,6 +103,8 @@ def parse_args():
if not os.path.isdir(arg):
err(arg, 5)
git_path = arg
elif opt in ('-c', '--cp_path'):
cp_path = arg
elif opt in ('-l', '--sftp_path'):
sftp_path = arg
elif opt in ('-d', '--debug'):
@ -109,8 +112,20 @@ def parse_args():
else:
err(arg, 4) #exit script if false parameter is detected
#if not path:
# err('path', 0)
if not sftp_host:
err('sftp_host', 0)
if not sftp_user:
err('sftp_user', 0)
if not sftp_passwd:
err('sftp_passwd', 0)
if not known_hosts:
err('known_hosts', 0)
if not sftp_host:
err('sftp_host', 0)
if not git_path:
err('git_path', 0)
if not sftp_path:
err('sftp_path', 0)
param = dict()
param['sftp_host'] = sftp_host
@ -119,6 +134,7 @@ def parse_args():
param['known_hosts'] = known_hosts
param['git_path'] = git_path
param['sftp_path'] = sftp_path
param['path_to_cp'] = cp_path
param['debug'] = debug
return param
@ -131,24 +147,53 @@ def calc_md5(filename):
for chunk in iter(lambda: file.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
progressDict={}
progressEveryPercent=10
def get_last_build(myhost, myname, mypasswd, known_hosts='known_hosts', bin_path='/jenkins/owrt'):
##
##for i in range(0,101):
## if i%progressEveryPercent==0:
## progressDict[str(i)]=""
##
##def printProgressDecimal(x,y):
## if int(100*(int(x)/int(y))) % progressEveryPercent ==0 and progressDict[str(int(100*(int(x)/int(y))))]=="":
## print("{}% ({} Transfered(B)/ {} Total File Size(B))".format(str("%.2f" %(100*(int(x)/int(y)))),x,y))
## progressDict[str(int(100*(int(x)/int(y))))]="1"
##
def sftp_connect(myhost, myname, mypasswd, known_hosts='known_hosts'):
cnopts = pysftp.CnOpts()
cnopts.hostkeys.load(known_hosts)
sftp = pysftp.Connection(host=myhost, username=myname, password=mypasswd, cnopts=cnopts)
#print('Conn success')
return pysftp.Connection(host=myhost, username=myname, password=mypasswd, cnopts=cnopts)
def get_last_build(sftp, bin_path='/jenkins/owrt'):
sftp.cwd(bin_path)
directory_structure = sftp.listdir_attr()
sftp.close()
files = []
for attr in directory_structure:
files.append(attr.filename)
files.sort()
return files[-1]
def cp_build_to_server(sftp, sftp_path, dir_to_cp, foldername):
#print(sftp_path)
#print(dir_to_cp)
#print(os.getcwd())
#print(foldername)
#print(sftp_path + foldername)
sftp.makedirs(sftp_path + foldername, mode=755)
#list = sftp.listdir()
#print(list)
#sftp.chdir(foldername)
#print(sftp.pwd)
sftp.put_r(dir_to_cp, sftp_path + foldername) ##, callback=lambda x,y: printProgressDecimal(x,y))
return
def build_needed(current, last_build_version):
@ -165,8 +210,9 @@ def build_needed(current, last_build_version):
def main():
params = parse_args()
last = get_last_build(params['sftp_host'], params['sftp_user'], params['sftp_passwd'], known_hosts=params['known_hosts'], bin_path=params['sftp_path'])
sftp = sftp_connect(params['sftp_host'], params['sftp_user'], params['sftp_passwd'], known_hosts=params['known_hosts'])
last = get_last_build(sftp, bin_path=params['sftp_path'])
#print(last)
os.chdir(params['git_path'])
out = subprocess.check_output(['git', 'describe']).decode(sys.stdout.encoding).strip()
match = re.search(git_ver_pattern, out)
@ -175,8 +221,12 @@ def main():
current = match.group('version')
#print(last)
#print(current)
print(build_needed('r'+current, last))
build= build_needed('r'+current, last)
print(build)
if params['path_to_cp'] != '' and build:
#print(params['path_to_cp'])
cp_build_to_server(sftp, params['sftp_path'], params['path_to_cp'], 'r'+current)
sftp.close()
if __name__ == "__main__":
main()