grim/local-pipelines

999f8916e14e
Parents 550bfa8dee55
Children e0e7aaa7b515
clean up the script file and rename the variable
--- a/pipelines/pipeline.py Tue Jul 26 18:58:23 2016 -0500
+++ b/pipelines/pipeline.py Tue Jul 26 19:04:25 2016 -0500
@@ -28,7 +28,7 @@
def _determine_image(self, step):
return step.get("image", self.config.get("image"))
- def _build_script(self, step):
+ def _script(self, step):
fd, filename = tempfile.mkstemp(prefix='pipeline', suffix='.sh')
filename = os.path.realpath(filename)
@@ -42,8 +42,7 @@
return filename
- def _get_command(self, step):
- script_filename = self._build_script(step)
+ def _get_command(self, step, script):
workdir = "/opt/atlassian/bitbucketci/agent/build"
labels = [
@@ -51,7 +50,7 @@
]
volumes = [
- "{filename}:{filename}:ro".format(filename=script_filename),
+ "{filename}:{filename}:ro".format(filename=script),
"{path}:{workdir}:rw".format(
path=self.build_path,
workdir=workdir,
@@ -70,7 +69,7 @@
" ".join(["--label " + l for l in labels]),
" ".join(["-e " + k + "=" + v for k, v in self.env.iteritems()]),
self._determine_image(step),
- script_filename,
+ script,
]
return " ".join(cmd)
@@ -80,8 +79,10 @@
def run(self):
return_code = 0
+
for n, step in enumerate(self._steps()):
- command = self._get_command(step)
+ script = self._script(step)
+ command = self._get_command(step, script)
try:
print('+ {}'.format(command))
@@ -95,5 +96,10 @@
proc.kill()
return_code = 1
break
+ finally:
+ try:
+ os.remove(script)
+ except OSError:
+ pass
return return_code