summaryrefslogtreecommitdiff
path: root/worker_manager
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-12-26 22:32:38 +0200
committerLars Wirzenius <liw@liw.fi>2017-12-27 18:00:21 +0200
commit5fe6641f9ba6fe17a182e924911fdd54d966ab69 (patch)
tree5046f98c6c7392651e9b1881e19db5f958cf5298 /worker_manager
parentf7eadacec1b26c34ca53e21af51dcb24afd58507 (diff)
downloadick2-5fe6641f9ba6fe17a182e924911fdd54d966ab69.tar.gz
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.
Diffstat (limited to 'worker_manager')
-rwxr-xr-xworker_manager25
1 files changed, 23 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
+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(