Skip to content

Conversation

@Nimbusprogrammer
Copy link

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 the dir step 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

@Nimbusprogrammer Nimbusprogrammer requested a review from a team as a code owner December 7, 2025 07:46
Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your interest in fixing issue:

It needs a much broader approach, since there are many cases where an argument is available in Pipeline that should be replaced with a better alternative provided by other Pipeline steps.

Please use the contents of my previously closed pull request as a starting point for your change:

It provides the broader approach and addresses many more areas.

That broader approach needs tests to be added that verify the expected message is inserted into the console log. Look at the usages of assertLogContains in src/test/java/hudson/plugins/git/GitHooksTest.java and src/test/java/jenkins/plugins/git/GitUsernamePasswordBindingTest.java for examples of the technique that is needed.

I think that I closed that earlier pull request by accident. I'd love to have you use that pull request as your starting point, add tests to confirm the change works as expected, then it can be checked in the plugin Bill of Materials and in the acceptance test harness to confirm that the changes do not break other plugins or other use cases.

@github-actions github-actions bot added the tests Automated test addition or improvement label Dec 7, 2025
@Nimbusprogrammer
Copy link
Author

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.

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

Labels

tests Automated test addition or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-43052] Warn if "Additional Behaviors > Check out to a sub-directory" is used in a Pipeline project

3 participants