diff options
-rw-r--r-- | ick2/workapi.py | 32 | ||||
-rw-r--r-- | yarns/400-build.yarn | 8 | ||||
-rw-r--r-- | yarns/500-build-fail.yarn | 2 |
3 files changed, 29 insertions, 13 deletions
diff --git a/ick2/workapi.py b/ick2/workapi.py index 67fad81..62581c7 100644 --- a/ick2/workapi.py +++ b/ick2/workapi.py @@ -50,17 +50,7 @@ class WorkAPI(ick2.APIbase): pipeline['status'] = 'building' self._update_pipeline(project, pipeline) - next_build_id = project.get('next_build_id') - if next_build_id is None: - next_build_id = 1 - build_id = '{}/{}'.format(project['project'], next_build_id) - ick2.log.log( - 'info', msg_text='build id chosen', - old_next_build_id=next_build_id, chosen_build_id=build_id) - project['next_build_id'] = next_build_id + 1 - self._projects.update_project(project) - - self._start_build(project, pipeline, worker, build_id) + build_id = self._start_build(project, pipeline, worker) self._start_log(build_id) build = self._get_build(build_id) actions = build['actions'] @@ -84,6 +74,16 @@ class WorkAPI(ick2.APIbase): return worker_state['doing'] + def _pick_build_number(self, project): + old_build_no = project.get('next_build_id') + build_no = (old_build_no or 0) + 1 + project['next_build_id'] = build_no + self._projects.update_project(project) + ick2.log.log( + 'info', msg_text='chose build number', + old_build_no=old_build_no, build_no=build_no) + return build_no + def _pick_triggered_pipeline(self): projects = self._projects.get_projects() for project in projects: @@ -104,8 +104,13 @@ class WorkAPI(ick2.APIbase): self._pinstances.add_instance( project_name, pipeline_name, pipeline_instance) - def _start_build(self, project, pipeline, worker, build_id): - ick2.log.log('info', msg_text='Starting new build', build_id=build_id) + def _start_build(self, project, pipeline, worker): + build_no = self._pick_build_number(project) + build_id = '{}/{}'.format(project['project'], build_no) + + ick2.log.log( + 'info', msg_text='Starting new build', build_id=build_id, + build_no=build_no) parameters = project.get('parameters', {}) create_workspace = { 'action': 'create_workspace', @@ -113,6 +118,7 @@ class WorkAPI(ick2.APIbase): actions = [create_workspace] + list(pipeline['actions']) build = { 'build_id': build_id, + 'build_number': build_no, 'log': '/logs/{}'.format(build_id), 'worker': worker, 'project': project['project'], diff --git a/yarns/400-build.yarn b/yarns/400-build.yarn index e28bccf..e0af107 100644 --- a/yarns/400-build.yarn +++ b/yarns/400-build.yarn @@ -181,6 +181,7 @@ User can now see pipeline is running and which worker is building it. ... "builds": [ ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -311,6 +312,7 @@ The build status now shows the next step as the active one. ... "builds": [ ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -408,6 +410,7 @@ no current action. ... "builds": [ ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -431,6 +434,7 @@ no current action. AND body matches ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -482,6 +486,7 @@ Start build again. This should become build number 2. ... "builds": [ ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -499,6 +504,7 @@ Start build again. This should become build number 2. ... }, ... { ... "build_id": "rome/2", + ... "build_number": 2, ... "log": "/logs/rome/2", ... "worker": "obelix", ... "project": "rome", @@ -583,6 +589,7 @@ Start build again. This should become build number 2. ... "builds": [ ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -600,6 +607,7 @@ Start build again. This should become build number 2. ... }, ... { ... "build_id": "rome/2", + ... "build_number": 2, ... "log": "/logs/rome/2", ... "worker": "obelix", ... "project": "rome", diff --git a/yarns/500-build-fail.yarn b/yarns/500-build-fail.yarn index 39a2e32..cde859f 100644 --- a/yarns/500-build-fail.yarn +++ b/yarns/500-build-fail.yarn @@ -141,6 +141,7 @@ Also, there's a build with a log. ... "builds": [ ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", @@ -162,6 +163,7 @@ Also, there's a build with a log. AND body matches ... { ... "build_id": "rome/1", + ... "build_number": 1, ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", |