11package hudson .plugins .git ;
22
3+ import jenkins .plugins .git .GitSampleRepoRule ;
4+ import jenkins .plugins .git .junit .jupiter .WithGitSampleRepo ;
35import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
46import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
57import org .jenkinsci .plugins .workflow .job .WorkflowRun ;
6- import org .junit .jupiter .api .Test ;
7- import org .junit .jupiter .api .BeforeEach ;
8- import org .junit .jupiter .api .AfterEach ;
98import org .jvnet .hudson .test .JenkinsRule ;
109import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
11- import jenkins .plugins .git .GitSampleRepoRule ;
10+ import org .junit .jupiter .api .BeforeEach ;
11+ import org .junit .jupiter .api .Test ;
1212
1313@ WithJenkins
14+ @ WithGitSampleRepo
1415public class RelativeTargetDirectoryPipelineTest {
1516
16- public GitSampleRepoRule sampleRepo = new GitSampleRepoRule ();
17+ private JenkinsRule r ;
18+ private GitSampleRepoRule sampleRepo ;
1719
1820 @ BeforeEach
19- public void setupRepo () throws Throwable {
20- sampleRepo .before ();
21- }
22-
23- @ AfterEach
24- public void tearDownRepo () {
25- sampleRepo .after ();
26- }
21+ void beforeEach (JenkinsRule rule , GitSampleRepoRule repo ) throws Exception {
22+ this .r = rule ;
23+ this .sampleRepo = repo ;
2724
28- @ Test
29- public void warningIsLoggedWhenUsedInPipeline (JenkinsRule j ) throws Exception {
30- // 1. Init a git repo
3125 sampleRepo .init ();
3226 sampleRepo .write ("Jenkinsfile" , "echo 'hello'" );
3327 sampleRepo .git ("add" , "Jenkinsfile" );
3428 sampleRepo .git ("commit" , "--all" , "-m" , "init" );
29+ }
3530
36- // 2. Create Pipeline Job
37- WorkflowJob job = j .createProject (WorkflowJob .class , "test-job" );
31+ @ Test
32+ void warningIsLoggedWhenUsedInPipeline () throws Exception {
33+ WorkflowJob job = r .jenkins .createProject (WorkflowJob .class , "test-job" );
3834 String repoUrl = sampleRepo .toString ();
3935
40- // 3. Script that uses the bad feature
4136 String pipelineScript =
4237 "node {\n " +
4338 " checkout([$class: 'GitSCM',\n " +
@@ -48,8 +43,8 @@ public void warningIsLoggedWhenUsedInPipeline(JenkinsRule j) throws Exception {
4843 "}\n " ;
4944 job .setDefinition (new CpsFlowDefinition (pipelineScript , true ));
5045
51- // 4. Run and Assert
52- WorkflowRun run = j . buildAndAssertSuccess ( job );
53- j .assertLogContains ("'Check out to a sub-directory' is not intended for use with Pipeline jobs " , run );
46+ WorkflowRun run = r . buildAndAssertSuccess ( job );
47+ r . assertLogContains ( "'Check out to a sub-directory' is not intended for use with Pipeline jobs" , run );
48+ r .assertLogContains ("Please use the 'dir' step instead " , run );
5449 }
5550}
0 commit comments