issue #1;#2

implemented issue #1 and #2

send email in post_build instead of catch()
This commit is contained in:
psycho 2021-02-01 22:41:46 +01:00
parent 976e913118
commit 5ca27fcf56

21
Jenkinsfile vendored
View File

@ -15,8 +15,10 @@ sftp_user = ''
sftp_path = '/jenkins/owrt/' sftp_path = '/jenkins/owrt/'
isBuildNeeded = false isBuildNeeded = false
deleteUnbuild = true deleteUnbuild = true
force_build = false
pre_clean = true pre_clean = true
post_clean = false post_clean = false
build_node = 'linux'
bin_path = 'bin' bin_path = 'bin'
core_count_str = '$((`nproc` + 1))' core_count_str = '$((`nproc` + 1))'
statusCode = 0 statusCode = 0
@ -63,6 +65,14 @@ if(params.BIN_PATH)
{ {
bin_path = params.BIN_PATH bin_path = params.BIN_PATH
} }
if(params.FORCE_BUILD)
{
force_build = params.FORCE_BUILD
}
if(params.BUILD_NODE)
{
build_node = params.BUILD_NODE
}
def printDebug(msg) def printDebug(msg)
{ {
@ -78,12 +88,12 @@ printDebug(currentBuild.id.toString())
printDebug(JOB_NAME) printDebug(JOB_NAME)
node('test') node(build_node)
{ {
try try
{ {
checkout() checkout()
if(isBuildNeeded) if(isBuildNeeded || force_build)
{ {
pre_build() pre_build()
build() build()
@ -93,7 +103,6 @@ node('test')
{ {
printDebug(e.getMessage()) printDebug(e.getMessage())
add2mail(e.getMessage()) add2mail(e.getMessage())
handle_failure()
} }
finally finally
{ {
@ -189,8 +198,10 @@ def post_build()
{ {
cleanWs() cleanWs()
} }
send_mail()
if((!isBuildNeeded && deleteUnbuild)) if((!isBuildNeeded && !force_build && deleteUnbuild))
{ {
//if no build is needed, then the last build is deleted and the next build number is set to previous build number //if no build is needed, then the last build is deleted and the next build number is set to previous build number
def job = Jenkins.instance.getItem(JOB_NAME) def job = Jenkins.instance.getItem(JOB_NAME)
@ -199,7 +210,7 @@ def post_build()
} }
} }
def handle_failure() def send_mail()
{ {
//def body_text = "${JOB_NAME} - Build # ${BUILD_NUMBER} - ${currentBuild.currentResult}:<br>Check console output at ${BUILD_URL} to view the results." //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.") add2mail("Check console output at ${BUILD_URL} to view the results.")