forked from openshift-eng/aos-cd-jobs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
53 lines (46 loc) · 1.7 KB
/
script.py
File metadata and controls
53 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import absolute_import, print_function, unicode_literals
from jinja2 import Template
from actions.named_shell_task import render_task
from .interface import Action
_SCRIPT_TITLE = "EXECUTE A SCRIPT ON THE REMOTE HOST"
_SCRIPT_ACTION_TEMPLATE = Template("""script="$( mktemp )"
cat <<SCRIPT >"${script}"
#!/bin/bash
set -o errexit -o nounset -o pipefail -o xtrace
{%- if repository %}
cd "\${GOPATH}/src/github.com/openshift/{{ repository }}"
{%- else %}
cd "\${HOME}"
{%- endif %}
{{ command | replace("$", "\$") }}
SCRIPT
chmod +x "${script}"
scp -F ${WORKSPACE}/.config/origin-ci-tool/inventory/.ssh_config "${script}" openshiftdevel:"${script}"
ssh -F ${WORKSPACE}/.config/origin-ci-tool/inventory/.ssh_config -t openshiftdevel "bash -l -c \\"timeout {{ timeout }} ${script}\\"" """)
class ScriptAction(Action):
"""
A ScriptAction generates a build step in which
the given script is run on the remote host. If
a repository is given, the script is run with
the repository as the working directory.
"""
def __init__(self, repository, script, title, timeout, output_format):
self.repository = repository
self.script = script
if title == None:
title = _SCRIPT_TITLE
if timeout == None:
timeout = 14400
self.title = title
self.timeout = timeout
self.output_format = output_format
def generate_build_steps(self):
return [render_task(
title=self.title,
command=_SCRIPT_ACTION_TEMPLATE.render(
repository=self.repository,
command=self.script,
timeout=self.timeout
),
output_format=self.output_format
)]