diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 6e41dd49074..8e1cf8a1e16 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -2586,6 +2586,10 @@ class SharedComputeEnvironment(SimpleComputeEnvironment): def working_directory(self): return self.job_wrapper.working_directory + def env_config_directory(self): + """Working directory (possibly as environment variable evaluation).""" + return "$_GALAXY_JOB_DIR" + def new_file_path(self): return os.path.abspath(self.app.config.new_file_path) diff --git a/lib/galaxy/jobs/runners/pulsar.py b/lib/galaxy/jobs/runners/pulsar.py index 9d607a22acd..bd3633a52ee 100644 --- a/lib/galaxy/jobs/runners/pulsar.py +++ b/lib/galaxy/jobs/runners/pulsar.py @@ -382,6 +382,16 @@ class PulsarJobRunner(AsynchronousJobRunner): if os.path.exists(tool_script): log.debug("Registering tool_script for Pulsar transfer [%s]" % tool_script) job_directory_files.append(tool_script) + # Following is job destination environment variables + env = client.env + # extend it with tool defined environment variables + tool_envs = job_wrapper.environment_variables + env.extend(tool_envs) + for tool_env in tool_envs: + job_directory_path = tool_env.get("job_directory_path") + if job_directory_path: + config_files.append(job_directory_path) + client_job_description = ClientJobDescription( command_line=command_line, input_files=input_files, @@ -392,7 +402,7 @@ class PulsarJobRunner(AsynchronousJobRunner): tool=job_wrapper.tool, config_files=config_files, dependencies_description=dependencies_description, - env=client.env, + env=env, rewrite_paths=rewrite_paths, arbitrary_files=path_rewrites_unstructured, touch_outputs=output_names, @@ -1056,6 +1066,9 @@ class PulsarComputeEnvironment(ComputeEnvironment): def working_directory(self): return self._working_directory + def env_config_directory(self): + return self.config_directory() + def config_directory(self): return self._config_directory diff --git a/lib/galaxy/tools/evaluation.py b/lib/galaxy/tools/evaluation.py index 84ca3b9f8fc..9de9998c145 100644 --- a/lib/galaxy/tools/evaluation.py +++ b/lib/galaxy/tools/evaluation.py @@ -540,13 +540,14 @@ class ToolEvaluator: is_template = False else: is_template = True - with tempfile.NamedTemporaryFile(dir=directory, delete=False) as temp: + with tempfile.NamedTemporaryFile(dir=directory, prefix="tool_env_", delete=False) as temp: config_filename = temp.name self.__write_workdir_file(config_filename, environment_variable_template, param_dict, is_template=is_template, strip=environment_variable_def.get("strip", False)) config_file_basename = os.path.basename(config_filename) # environment setup in job file template happens before `cd $working_directory` - environment_variable["value"] = '`cat "$_GALAXY_JOB_DIR/%s"`' % config_file_basename + environment_variable["value"] = '`cat "%s/%s"`' % (self.compute_environment.env_config_directory(), config_file_basename) environment_variable["raw"] = True + environment_variable["job_directory_path"] = config_filename environment_variables.append(environment_variable) home_dir = self.compute_environment.home_directory() diff --git a/test/integration/test_pulsar_embedded.py b/test/integration/test_pulsar_embedded.py index 8352e6b1ae4..411daad976e 100644 --- a/test/integration/test_pulsar_embedded.py +++ b/test/integration/test_pulsar_embedded.py @@ -25,4 +25,5 @@ test_tools = integration_util.integration_tool_runner([ "multi_data_param", "output_filter", "vcf_bgzip_test", + "environment_variables", ])