Skip to content

Fix Azure Batch executor scratch directory support#6872

Open
adamrtalbot wants to merge 2 commits intomasterfrom
fix/azure-batch-scratch
Open

Fix Azure Batch executor scratch directory support#6872
adamrtalbot wants to merge 2 commits intomasterfrom
fix/azure-batch-scratch

Conversation

@adamrtalbot
Copy link
Collaborator

Summary

  • Fix process.scratch = true failing on Azure Batch with /bin/bash: .command.sh: No such file or directory
  • Fix .command.in resource file incorrectly sourced from .command.sh blob URL in AzBatchService.resourceFileUrls()

Problem

When process.scratch = true, the .command.run script creates a temporary scratch directory and cds into it before executing. However, .command.sh and other control files remain in the Azure Batch task working directory (where Azure downloaded them as resource files), so nxf_launch() fails with a "No such file or directory" error.

Both AWS Batch and Google Batch handle this by staging .command.sh as an input file. AWS re-downloads from S3 (necessary since only .command.run is bootstrapped). Google uses local filesystem copies via mounted GCS.

Fix

Azure Batch already downloads .command.sh, .command.run, and .command.in as resource files to the task working directory before execution — so re-downloading from blob storage is unnecessary.

Instead, this fix:

  1. Saves the original working directory as NXF_TASK_LAUNCH_DIR in AzFileCopyStrategy.getEnvScript() — this runs before the template's cd $NXF_SCRATCH, capturing where the resource files live
  2. Copies control files locally in AzFileCopyStrategy.getStageInputFilesScript() — after cd $NXF_SCRATCH, copies .command.sh, .command.run, and .command.in from the saved directory using a local cp (no network round-trip)

The generated staging block:

if [[ "${NXF_SCRATCH:-}" && "${NXF_TASK_LAUNCH_DIR:-}" && "$NXF_TASK_LAUNCH_DIR" != "$PWD" ]]; then
  cp "$NXF_TASK_LAUNCH_DIR"/.command.sh . 2>/dev/null || true
  cp "$NXF_TASK_LAUNCH_DIR"/.command.run . 2>/dev/null || true
  cp "$NXF_TASK_LAUNCH_DIR"/.command.in . 2>/dev/null || true
fi

Bonus fix

AzBatchService.resourceFileUrls() was using cmdScript (.command.sh's blob URL) as the HTTP source for the .command.in resource file, meaning Azure Batch would download .command.sh content and save it as .command.in. Fixed to use the correct .command.in blob path.

Testing

  • Updated existing AzFileCopyStrategyTest assertions for the new staging and env output
  • Verified with a real Azure Batch run using nextflow run hello with process.scratch = true

When process.scratch is enabled, the .command.run script changes to a
temporary scratch directory before executing. However, .command.sh and
other control files remain in the Azure Batch task working directory,
causing 'No such file or directory' errors.

Fix by saving the original working directory as NXF_TASK_LAUNCH_DIR in
the environment setup (before the scratch cd), then copying task control
files (.command.sh, .command.run, .command.in) from that directory to
the scratch directory during staging. This uses a local copy instead of
re-downloading from Azure Blob Storage, since Azure Batch already
downloads these files as resource files to the task working directory.

Also fix a bug in AzBatchService.resourceFileUrls() where the
.command.in resource file was incorrectly sourced from the .command.sh
blob URL instead of the actual stdin file URL.

Generated by Claude Code

Signed-off-by: adamrtalbot <12817534+adamrtalbot@users.noreply.github.com>
@netlify
Copy link

netlify bot commented Feb 26, 2026

Deploy Preview for nextflow-docs-staging ready!

Name Link
🔨 Latest commit b347721
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/69a07b4ad3666e0008251289
😎 Deploy Preview https://deploy-preview-6872--nextflow-docs-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants