From 5fe6641f9ba6fe17a182e924911fdd54d966ab69 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 26 Dec 2017 22:32:38 +0200 Subject: Add: pass params to shell, Python actions We generate JSON from the parameters, and then base64 encode that to emake it easy to pass to the code snippet from the pipeline step. This avoids having to jump through hoops to use a temporary file. --- worker_manager | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'worker_manager') diff --git a/worker_manager b/worker_manager index 1d78207..92c2ad4 100755 --- a/worker_manager +++ b/worker_manager @@ -15,6 +15,7 @@ # along with this program. If not, see . +import base64 import json import logging import sys @@ -231,10 +232,30 @@ class WorkerManager(cliapp.Application): return exit_code def run_shell(shell_cmd): - return run_with_interp(['bash', '-xeuc'], shell_cmd) + params = work.get('parameters', {}) + params_json = json.dumps(params) + params_text = base64.b64encode( + params_json.encode('utf8')).decode('utf8') + prefix = [ + 'params() { echo -n "%s" | base64 -d; }' % params_text, + ] + prefix_text = ''.join('{}\n'.format(line) for line in prefix) + script = prefix_text + shell_cmd + return run_with_interp(['bash', '-xeuc'], script) def run_python(python_cmd): - return run_with_interp(['python3', '-c'], python_cmd) + params = work.get('parameters', {}) + params_json = json.dumps(params) + params_text = base64.b64encode( + params_json.encode('utf8')).decode('utf8') + prefix = [ + 'import base64, json', + 'params = json.loads(base64.b64decode(' + ' "{}").decode("utf8"))'.format(params_text) + ] + prefix_text = ''.join('{}\n'.format(line) for line in prefix) + script = prefix_text + python_cmd + return run_with_interp(['python3', '-c'], script) def run_debootstrap(step): shell_cmd = "sudo debootstrap '{}' . '{}'".format( -- cgit v1.2.1