summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-04-15 19:05:55 +0300
committerLars Wirzenius <liw@liw.fi>2018-04-15 19:05:55 +0300
commite4cb32628c7547d08316ecc08788c0977ba71260 (patch)
treeade0d4d068cb28f143e77211b871f53fdee4b5d4
parentf3b1a5ee1f737ad5325dcc14cf7e0ac6f76d59d2 (diff)
parente8087c03e48b23d051611d913c5726765ae5140b (diff)
downloadick2-e4cb32628c7547d08316ecc08788c0977ba71260.tar.gz
Merge: give build actions build number via environment
-rw-r--r--NEWS5
-rw-r--r--ick2/actionenvs.py5
-rw-r--r--ick2/actions.py8
-rw-r--r--ick2/workapi.py6
-rw-r--r--ick2/workapi_tests.py3
-rwxr-xr-xworker_manager2
-rw-r--r--yarns/400-build.yarn13
-rw-r--r--yarns/500-build-fail.yarn1
8 files changed, 40 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index cc1b6cc..6113c1c 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,11 @@ Version 0.36+git, not yet released
* `icktool trigger` now works. There was a bug in how the controller
response was printed out.
+* Worker-manager now gives all the child processes it runs the build
+ number as the `BUILD_NUMBER` environment variable. This lets
+ pipeline actions do things like embed it in Debian package versions
+ for CI builds.
+
Version 0.36, released 2018-04-08
----------------------------------
diff --git a/ick2/actionenvs.py b/ick2/actionenvs.py
index 099b13f..e09366b 100644
--- a/ick2/actionenvs.py
+++ b/ick2/actionenvs.py
@@ -103,6 +103,10 @@ class ActionEnvironment: # pragma: no cover
self._systree = systree
self._workspace = workspace
self._reporter = reporter
+ self._extra_env = {}
+
+ def set_extra_env(self, extra_env):
+ self._extra_env = dict(extra_env)
def get_systree_directory(self):
return self._systree
@@ -132,6 +136,7 @@ class ActionEnvironment: # pragma: no cover
'LC_ALL': 'C',
'DEBIAN_FRONTEND': 'noninteractive',
})
+ env.update(self._extra_env)
return env
diff --git a/ick2/actions.py b/ick2/actions.py
index ab23edc..9f444e0 100644
--- a/ick2/actions.py
+++ b/ick2/actions.py
@@ -41,6 +41,10 @@ class ActionFactory:
self._reporter = reporter
self._token = None
self._blob_url = None
+ self._extra_env = {}
+
+ def add_env_var(self, name, value): # pragma: no cover
+ self._extra_env[name] = value
def set_token(self, token):
self._token = token
@@ -68,7 +72,9 @@ class ActionFactory:
env_class = self._classes[env]
area = self.get_workspace_area()
ws = area.create_workspace(project_name)
- return env_class(self._systree, ws.get_directory(), self._reporter)
+ env = env_class(self._systree, ws.get_directory(), self._reporter)
+ env.set_extra_env(self._extra_env)
+ return env
def create_action(self, spec, project_name):
env = self.create_environment(spec, project_name)
diff --git a/ick2/workapi.py b/ick2/workapi.py
index 62581c7..a23f603 100644
--- a/ick2/workapi.py
+++ b/ick2/workapi.py
@@ -50,7 +50,8 @@ class WorkAPI(ick2.APIbase):
pipeline['status'] = 'building'
self._update_pipeline(project, pipeline)
- build_id = self._start_build(project, pipeline, worker)
+ build_id, build_no = self._start_build(
+ project, pipeline, worker)
self._start_log(build_id)
build = self._get_build(build_id)
actions = build['actions']
@@ -58,6 +59,7 @@ class WorkAPI(ick2.APIbase):
doing = {
'build_id': build_id,
+ 'build_number': build_no,
'worker': worker,
'project': project['project'],
'pipeline': pipeline['pipeline'],
@@ -129,7 +131,7 @@ class WorkAPI(ick2.APIbase):
'current_action': 0,
}
self._builds.add(build_id, build)
- return build_id
+ return build_id, build_no
def _get_build(self, build_id):
return self._builds.get(build_id)
diff --git a/ick2/workapi_tests.py b/ick2/workapi_tests.py
index fdfc601..1ee4625 100644
--- a/ick2/workapi_tests.py
+++ b/ick2/workapi_tests.py
@@ -80,6 +80,7 @@ class WorkAPITests(unittest.TestCase):
work = self.create_work_api()
expected = {
'build_id': 'foo/1',
+ 'build_number': 1,
'worker': 'asterix',
'project': 'foo',
'pipeline': 'build',
@@ -105,6 +106,7 @@ class WorkAPITests(unittest.TestCase):
# Ask for some work.
expected = {
'build_id': 'foo/1',
+ 'build_number': 1,
'worker': 'asterix',
'project': 'foo',
'pipeline': 'build',
@@ -172,6 +174,7 @@ class WorkAPITests(unittest.TestCase):
# Ask for some work.
expected = {
'build_id': 'foo/1',
+ 'build_number': 1,
'worker': 'asterix',
'project': 'foo',
'pipeline': 'build',
diff --git a/worker_manager b/worker_manager
index 1590109..cd2c884 100755
--- a/worker_manager
+++ b/worker_manager
@@ -198,12 +198,14 @@ class Worker:
def do_work(self, work):
project_name = work['project']
+ build_number = work['build_number']
step = work.get('step', {})
params = work.get('parameters', {})
reporter = ick2.Reporter(self._api, work)
af = ick2.ActionFactory(self._systree, self._workspace, reporter)
af.set_token(self._api.get_token())
af.set_blob_url_func(self._api.get_blob_upload_url)
+ af.add_env_var('BUILD_NUMBER', str(build_number))
action = af.create_action(step, project_name)
exit_code = action.execute(params, step)
diff --git a/yarns/400-build.yarn b/yarns/400-build.yarn
index bd44122..3ee30a6 100644
--- a/yarns/400-build.yarn
+++ b/yarns/400-build.yarn
@@ -118,6 +118,7 @@ the worker to construct a new workspace for the build.
AND body matches
... {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",
@@ -135,6 +136,7 @@ the worker to construct a new workspace for the build.
AND body matches
... {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",
@@ -163,6 +165,7 @@ User can now see pipeline is running and which worker is building it.
... "worker": "obelix",
... "doing": {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",
@@ -230,6 +233,7 @@ Worker requests more work, and gets the first actual build step.
AND body matches
... {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",
@@ -266,6 +270,7 @@ didnt't finish.
AND body matches
... {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",
@@ -341,6 +346,7 @@ Now there's another step to do.
AND body matches
... {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",
@@ -362,6 +368,7 @@ User sees changed status.
... "worker": "obelix",
... "doing": {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "worker": "obelix",
... "project": "rome",
... "pipeline": "construct",
@@ -469,6 +476,7 @@ Start build again. This should become build number 2.
AND body matches
... {
... "build_id": "rome/2",
+ ... "build_number": 2,
... "log": "/logs/rome/2",
... "worker": "obelix",
... "project": "rome",
@@ -543,6 +551,7 @@ Start build again. This should become build number 2.
AND body matches
... {
... "build_id": "rome/2",
+ ... "build_number": 2,
... "log": "/logs/rome/2",
... "worker": "obelix",
... "project": "rome",
@@ -705,6 +714,7 @@ Build the first project.
WHEN worker-manager makes request POST /work with a valid token and body
... {
... "build_id": "first/1",
+ ... "build_number": 1,
... "worker": "obelix",
... "project": "first",
... "pipeline": "do_something",
@@ -724,6 +734,7 @@ Build the first project.
WHEN worker-manager makes request POST /work with a valid token and body
... {
... "build_id": "first/1",
+ ... "build_number": 1,
... "worker": "obelix",
... "project": "first",
... "pipeline": "do_something",
@@ -894,6 +905,7 @@ Trigger both projects.
WHEN asterix makes request POST /work with a valid token and body
... {
... "build_id": "first/1",
+ ... "build_number": 1,
... "worker": "asterix",
... "project": "first",
... "pipeline": "do_something",
@@ -919,6 +931,7 @@ Trigger both projects.
WHEN obelix makes request POST /work with a valid token and body
... {
... "build_id": "second/1",
+ ... "build_number": 1,
... "worker": "obelix",
... "project": "second",
... "pipeline": "do_something",
diff --git a/yarns/500-build-fail.yarn b/yarns/500-build-fail.yarn
index dbe4e2c..95fcd5e 100644
--- a/yarns/500-build-fail.yarn
+++ b/yarns/500-build-fail.yarn
@@ -85,6 +85,7 @@ Worker wants work and gets the first step to run.
AND body matches
... {
... "build_id": "rome/1",
+ ... "build_number": 1,
... "log": "/logs/rome/1",
... "worker": "obelix",
... "project": "rome",