From: hyokeun Date: Fri, 14 Jul 2017 07:18:57 +0000 (+0900) Subject: Keep build numbers when re-installing jenkins X-Git-Tag: submit/trunk/20190927.012743~376^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F98%2F138898%2F1;p=services%2Fjenkins-scripts.git Keep build numbers when re-installing jenkins Change-Id: I3659333f59082e33770d0a363c06f045b91a0a84 --- diff --git a/groovy_init_scripts/init.groovy b/groovy_init_scripts/init.groovy index 4ac9de8..7fd625c 100644 --- a/groovy_init_scripts/init.groovy +++ b/groovy_init_scripts/init.groovy @@ -19,6 +19,26 @@ def mx = { filepath -> this.metaClass.mixin script } +// New container have their all jobs nextBuildNumber=1 if it is restarted prior to deploy. +// Below will keep current build numbers. +def setNextBuildNumber = { + jobs = Jenkins.instance.projects.collect { it.name } + jobs.each() { job -> + set_num = 0 + new File(env['JENKINS_HOME'] + '/jobs/' + job + '/builds').eachDir() { dir -> + def thisdir = dir.getName().split("\\.")[0] + if (thisdir.isNumber()) { + if (thisdir.toInteger() > set_num) { + set_num = thisdir.toInteger() + } + } + } + item = Jenkins.instance.getItemByFullName(job) + item.updateNextBuildNumber(set_num + 1) + item.save() + } +} + Properties properties = new Properties() try { properties.load(new FileInputStream(env['JENKINS_HOME'] + '/.groovy_init_required')) @@ -35,6 +55,11 @@ if (properties.CONTAINER_INIT_REQUIRED == null || properties.CONTAINER_INIT_REQU new File(env['JENKINS_HOME'] + '/.groovy_init_required').delete() /////////////////////////////////////////////////////////////////// +/////////// Update proper build numbers for each job //////////// +/////////////////////////////////////////////////////////////////// +setNextBuildNumber() + +/////////////////////////////////////////////////////////////////// /////////////////// E-mail Notification ///////////////////////// /////////////////////////////////////////////////////////////////// if (properties.SMTP_HOST != null && properties.SMTP_HOST != '') {