Add pre-job and post-job execution support to BashV3 task#21876
Open
nickymunga wants to merge 2 commits intomicrosoft:masterfrom
Open
Add pre-job and post-job execution support to BashV3 task#21876nickymunga wants to merge 2 commits intomicrosoft:masterfrom
nickymunga wants to merge 2 commits intomicrosoft:masterfrom
Conversation
Enables users to run setup scripts before job execution and cleanup scripts after job completion. Pre-job scripts can prepare environments and download resources, while post-job scripts handle cleanup without failing the pipeline. Includes comprehensive test coverage for all execution phases.
- Use tl.loc() for skip messages in prebash.ts and postbash.ts - Include exit code in post-job failure warning message - Update test assertions to expect localized mock strings Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This PR adds pre-job and post-job script execution capabilities to the BashV3 task, enabling users to run setup and cleanup scripts alongside their main bash script execution. This addresses the need for task-level lifecycle hooks commonly used for environment setup, dependency installation, and cleanup operations.
Task Name
BashV3
Description
preJobScriptandpostJobScriptinputs to BashV3 taskbashrunner.tsto eliminate code duplication across entry pointsprebash.tsfor pre-job execution (runs before main script)postbash.tsfor post-job execution (runs after main script, never fails the pipeline)tl.loc()Risk Assessment (Low / Medium / High)
Low
Reasoning:
Change Behind Feature Flag (Yes / No)
No
This change does not require a feature flag because:
Tech Design / Approach
Design Pattern: Extracted common bash execution logic to eliminate duplication
bashrunner.tswithrunBashScript()function acceptingBashRunnerOptionsinterfacebash.tsfrom 233 lines to 32 lines using shared logicprebash.tsandpostbash.tsuse same shared execution logicArchitectural Decisions:
prejobexecution,execution,postjobexecutionsetResultparameter torunBashScript()to allow post-job to control result settingBashResultinterface with exit code and result status for inspectionTrade-offs:
Documentation Changes Required (Yes/No)
Yes
preJobScript: "Optional bash script to run before the job starts..."postJobScript: "Optional bash script to run after the job completes..."Unit Tests Added or Updated (Yes / No)
Yes
Added 5 new test files covering all scenarios:
L0PreJob.ts- Successful pre-job script executionL0PreJobSkip.ts- Skip when no pre-job script providedL0PostJob.ts- Successful post-job script executionL0PostJobSkip.ts- Skip when no post-job script providedL0PostJobFailure.ts- Post-job resilience (task succeeds with warning when post-job fails)Updated
L0.tswith test assertions for all new functionality.Additional Testing Performed
node make.js build --task BashV3 --BypassNpmAuditLogging Added/Updated (Yes/No)
Yes
tl.loc()Telemetry Added/Updated (Yes/No)
No
No new telemetry added. Existing telemetry in bashrunner.ts for argument validation errors is preserved from original bash.ts implementation.
Rollback Scenario and Process (Yes/No)
Yes
Dependency Impact Assessed and Regression Tested (Yes/No)
Yes
Checklist