def debug = false def stageName = '' def git_link def script_git = 'https://git.psychobox.org/psycho/owrt_build_script.git' def git_folder = 'openwrt' def script_folder = 'owrt_build_script' def config_path = script_folder + '/configs/' def patch_path = script_folder + '/patches/' def scripts_path = script_folder + '/scripts/' def patch = patch_path + 'tl-wr841_16m.patch' def sftp_host = '' def sftp_user = '' //def sftp_passwd = '' def sftp_path = '/jenkins/owrt/' def isBuildNeeded = false def deleteUnbuild = true def pre_clean = true def post_clean = false def bin_path = 'bin' if(params.DEBUG) { debug = true } if(params.GIT) { git_link = params.GIT } if(params.SFTP_HOST) { sftp_host = params.SFTP_HOST } if(params.SFTP_USER) { sftp_user = params.SFTP_USER } if(params.SFTP_PATH) { sftp_path = params.SFTP_PATH } if(params.KNOWN_HOSTS) { known_hosts = params.KNOWN_HOSTS } if(params.DeleteUnbuild) { deleteUnbuild = params.DeleteUnbuild } if(params.PRE_CLEAN) { pre_clean = params.PRE_CLEAN } if(params.POST_CLEAN) { post_clean = params.POST_CLEAN } if(params.BIN_PATH) { bin_path = params.BIN_PATH } def printDebug(msg) { println 'DEBUG: ' + msg } printDebug(currentBuild.id.toString()) printDebug(JOB_NAME) node('test') { //currentbuild.result = 'SUCCESS' stage('checkout') { if(pre_clean) { cleanWs() } sh label: 'checkout_configs', script: 'git clone ' + script_git + ' ' + script_folder sh label: 'checkout_openwrt', script: 'git clone ' + git_link + ' ' + git_folder def ret = sh label: 'is_build_needed', 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, returnStdout: true if(ret.trim().equalsIgnoreCase('True')) { isBuildNeeded = true } } if(isBuildNeeded) { 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') { sh label: 'copy_config', script: 'cp ' + config_path + 'tl_wr841_config ' + git_folder + '/.config' sh label: 'build_v11', script: 'cd ' + git_folder + '; make defconfig; make -j$((`nproc` + 1))' } 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 } } if(post_clean) { stage('clean') { cleanWs() } } 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(jobName) job.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() } }