Warn when 'Check out to a sub-directory' is used with Pipeline jobs (fixes #3068)
Context
Using "Check out to a sub-directory" (RelativeTargetDirectory) in Pipeline jobs is confusing because Jenkins expects the Jenkinsfile in the workspace root, but this extension moves it to a subdirectory. The recommended approach for Pipelines is to use dir('subdir') { checkout scm }.
Changes
- Added a runtime check in
RelativeTargetDirectory.java. - If the current job is a Pipeline (
WorkflowJob), a warning is now printed to the build log advising the user to use thedirstep instead.
Testing
- Verified manually by creating a Pipeline job with the "Check out to a sub-directory" behavior.
- Confirmed the warning appears in the console output:
[Warning] 'Check out to a sub-directory' is not intended for use with Pipeline jobs. Please use the 'dir' step instead.
Fixes #3068
Thanks for the review. Summary of updates:
• Added an automated JUnit 5 test confirming that the warning is logged when RelativeTargetDirectory is used in a Pipeline job. • Test located at: src/test/java/hudson/plugins/git/RelativeTargetDirectoryPipelineTest.java • Verified the test passes locally.
Next steps: • Reviewing PR #1639 to understand the broader approach. • Will extend this fix incrementally based on that structure.
Appreciate the guidance.