diff --git a/cli/generators/cli.py b/cli/generators/cli.py index 0c1684c9..de65079c 100644 --- a/cli/generators/cli.py +++ b/cli/generators/cli.py @@ -29,6 +29,8 @@ class CliGenerator(BaseGenerator): initial_directory_variable: str = "AEOLUS_INITIAL_DIRECTORY" + template: Optional[typing.Any] = None + def __init__( self, windfile: WindFile, input_settings: InputSettings, output_settings: OutputSettings, metadata: PassMetadata ): @@ -194,8 +196,9 @@ def generate_using_jinja2(self) -> str: Generate the bash script to be used as a local CI system with jinja2. """ # Load the template from the file system - env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), "..", "templates"))) - template = env.get_template("cli.sh.j2") + if not self.template: + env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), "..", "templates"))) + self.template = env.get_template("cli.sh.j2") # Prepare your data data = { @@ -214,7 +217,7 @@ def generate_using_jinja2(self) -> str: } # Render the template with your data - rendered_script = template.render(data) + rendered_script = self.template.render(data) return rendered_script diff --git a/cli/templates/cli.sh.j2 b/cli/templates/cli.sh.j2 index bffdac49..20c489c0 100644 --- a/cli/templates/cli.sh.j2 +++ b/cli/templates/cli.sh.j2 @@ -5,12 +5,12 @@ set -e export {{ initial_directory_variable }}=${PWD} {%- endif -%} -{# Handling environment variables from windfile -#} -{%- for env_var in environment -%} +{%- if environment -%} +{% for env_var in environment -%} export {{ env_var }}="{{ environment[env_var] }}" {%- endfor -%} +{%- endif -%} -{# Additional functions based on steps -#} {%- for step in steps %} {{ step.name }} () { echo '⚙️ executing {{ step.name }}' @@ -71,7 +71,7 @@ set -e {% endfor -%} {%- if has_always_actions -%} -function final_aeolus_post_action () { +final_aeolus_post_action () { set +e # from now on, we don't exit on errors echo '⚙️ executing final_aeolus_post_action' cd {{ initial_directory }}