rebuilt script structure#9

rebuilt script structure#9
This commit is contained in:
psycho 2020-11-09 17:57:06 +01:00
parent e9f04ec4d6
commit 976e913118

88
Jenkinsfile vendored
View File

@ -12,19 +12,16 @@ scripts_path = script_folder + '/scripts/'
patch = patch_path + 'tl-wr841_16m.patch'
sftp_host = ''
sftp_user = ''
//def sftp_passwd = ''
sftp_path = '/jenkins/owrt/'
isBuildNeeded = false
deleteUnbuild = true
pre_clean = true
post_clean = false
bin_path = 'bin'
verbose = false
single_core = false
verbose_str = ''
core_count_str = '$((`nproc` + 1))'
statusCode = 0
mail_body = "<h1>${JOB_NAME} - Build # ${BUILD_NUMBER} - ${currentBuild.currentResult}:</h1>"
mail_subject = "${JOB_NAME} - Build # ${BUILD_NUMBER} - ${currentBuild.currentResult}!"
if(params.DEBUG)
{
@ -66,20 +63,16 @@ if(params.BIN_PATH)
{
bin_path = params.BIN_PATH
}
if(params.VERBOSE)
{
verbose = params.VERBOSE
}
if(params.SINGLE_CORE)
{
single_core = params.SINGLE_CORE
}
def printDebug(msg)
{
println 'DEBUG: ' + msg
}
def add2mail(msg)
{
mail_body += '<br>' + msg + '<br>'
}
printDebug(currentBuild.id.toString())
printDebug(JOB_NAME)
@ -98,7 +91,8 @@ node('test')
}
catch (e)
{
printDebug(e)
printDebug(e.getMessage())
add2mail(e.getMessage())
handle_failure()
}
finally
@ -117,8 +111,16 @@ def checkout()
{
cleanWs()
}
sh label: 'checkout_configs', script: 'git clone ' + script_git + ' ' + script_folder
sh label: 'checkout_openwrt', script: 'git clone ' + git_link + ' ' + git_folder
statusCode = sh label: 'checkout_configs', script: 'git clone ' + script_git + ' ' + script_folder, returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error checking out configs")
}
statusCode = sh label: 'checkout_openwrt', script: 'git clone ' + git_link + ' ' + git_folder, returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error checking out OWRT")
}
def ret = sh label: 'is_build_needed', script: 'set +x; python ' + scripts_path + 'sftp_test.py -a ' + sftp_host + ' -u ' + sftp_user + ' -p ' + params.SFTP_PASSWD + ' -g ' + git_folder + ' -f ' + scripts_path + known_hosts + ' -l ' + sftp_path + '; set -x', returnStdout: true
if(ret.trim().equalsIgnoreCase('True'))
{
@ -131,9 +133,21 @@ def 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'
statusCode = sh label: 'patch_sources', script: 'cd ' + git_folder + '; patch -p1 < ../' + patch, returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error patching sources")
}
statusCode = sh label: 'feeds_update', script: 'cd ' + git_folder + '; ./scripts/feeds update -a', returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error updating feeds")
}
statusCode = sh label: 'feeds_install', script: 'cd ' + git_folder + '; ./scripts/feeds install -a', returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error installing feeds")
}
}
}
@ -142,18 +156,30 @@ def build()
stage('build')
{
sh label: 'copy_config', script: 'cp ' + config_path + 'tl_wr841_config ' + git_folder + '/.config'
statusCode = sh label: 'build', script: 'cd ' + git_folder + '; make defconfig; make download; make -j$((`nproc` + 1))', returnStatus:true
printDebug(statusCode)
if(statusCode != 0)
{
throw new Exception("Error copying config")
}
statusCode = sh label: 'build', script: 'cd ' + git_folder + '; make defconfig; make download; make -j$((`nproc` + 1))', returnStatus:true
if(statusCode != 0)
{
add2mail('multicore failed')
printDebug('multicore build failed -> trying to build verbosely on a single core')
sh label: 'build_single_core', script: 'cd ' + git_folder + '; make defconfig; make download; make -j1 V=s'
statusCode = sh label: 'build_single_core', script: 'cd ' + git_folder + '; make defconfig; make download; make -j1 V=s', returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error building images")
}
}
}
stage('move_bin_to_ftp')
{
sh label: 'copy_binaries', script: 'python ' + scripts_path + 'sftp_test.py -a ' + sftp_host + ' -u ' + sftp_user + ' -p ' + params.SFTP_PASSWD + ' -g ' + git_folder + ' -f ' + scripts_path + known_hosts + ' -l ' + sftp_path + ' -c ' + bin_path
statusCode = sh label: 'copy_binaries', script: 'python ' + scripts_path + 'sftp_test.py -a ' + sftp_host + ' -u ' + sftp_user + ' -p ' + params.SFTP_PASSWD + ' -g ' + git_folder + ' -f ' + scripts_path + known_hosts + ' -l ' + sftp_path + ' -c ' + bin_path, returnStatus:true
if(statusCode != 0)
{
throw new Exception("Error copying binaries")
}
}
}
@ -167,25 +193,15 @@ def post_build()
if((!isBuildNeeded && deleteUnbuild))
{
//if no build is needed, then the last build is deleted and the next build number is set to previous build number
//def jobName = JOB_NAME
def job = Jenkins.instance.getItem(JOB_NAME)
job.getLastBuild().delete()
//Jenkins.instance.getItem(JOB_NAME).getLastBuild().delete()
//printDebug('NUMBER:' + job.nextBuildNumber)
//logger.printInfo('job is getting deleted ' + currentBuild.id.toString())//job.nextBuildNumber)
//job.nextBuildNumber -= 1 //updateNextBuildNumber(job.getNextBuildNumber() - 1) //resetting next build number does not work. if done, the next build start will do nothing
//job.saveNextBuildNumber()
//job.updateNextBuildNumber(job.nextBuildNumber - 1)
//printDebug('NUMBER_after:' + job.nextBuildNumber)
job.save()
}
}
def handle_failure()
{
def body_text = "${JOB_NAME} - Build # ${BUILD_NUMBER} - ${currentBuild.currentResult}:<br>Check console output at ${BUILD_URL} to view the results."
def subject_text = "${JOB_NAME} - Build # ${BUILD_NUMBER} - ${currentBuild.currentResult}!"
emailext body: body_text, subject: subject_text, to: 'psychowoife@gmail.com'
//def body_text = "${JOB_NAME} - Build # ${BUILD_NUMBER} - ${currentBuild.currentResult}:<br>Check console output at ${BUILD_URL} to view the results."
add2mail("Check console output at ${BUILD_URL} to view the results.")
emailext body: mail_body, subject: mail_subject, to: 'psychowoife@gmail.com'
}