40
40
import hudson .util .StreamTaskListener ;
41
41
import java .io .File ;
42
42
import java .io .IOException ;
43
+ import java .util .Collections ;
43
44
import java .util .Iterator ;
44
45
import java .util .List ;
45
46
import jenkins .model .Jenkins ;
46
47
47
48
import jenkins .plugins .git .GitSampleRepoRule ;
48
49
import jenkins .scm .impl .subversion .SubversionSampleRepoRule ;
49
50
import org .apache .commons .io .FileUtils ;
51
+ import org .hamcrest .Matchers ;
50
52
import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
51
53
import org .jenkinsci .plugins .workflow .cps .CpsScmFlowDefinition ;
52
54
import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
@@ -165,7 +167,7 @@ public void scmVars() throws Exception {
165
167
}
166
168
167
169
@ Issue (value = { "JENKINS-57918" , "JENKINS-59560" })
168
- @ Test public void scmParsesUmodifiedChangelogFile () {
170
+ @ Test public void scmParsesUnmodifiedChangelogFile () {
169
171
rr .then (r -> {
170
172
WorkflowJob p = r .jenkins .createProject (WorkflowJob .class , "p" );
171
173
p .setDefinition (new CpsFlowDefinition (
@@ -176,6 +178,46 @@ public void scmVars() throws Exception {
176
178
});
177
179
}
178
180
181
+ @ Test public void scmParsesChangelogFileFromFakeChangeLogSCM () {
182
+ rr .then (r -> {
183
+ WorkflowJob p = r .jenkins .createProject (WorkflowJob .class , "p" );
184
+ p .setDefinition (new CpsFlowDefinition (
185
+ "import org.jvnet.hudson.test.FakeChangeLogSCM\n " +
186
+ "def testSCM = new FakeChangeLogSCM()\n " +
187
+ "testSCM.addChange().withAuthor(/alice$BUILD_NUMBER/)\n " +
188
+ "node() {\n " +
189
+ " checkout(testSCM)\n " +
190
+ "}" , false ));
191
+ WorkflowRun b = r .buildAndAssertSuccess (p );
192
+ assertThat (b .getCulpritIds (), Matchers .equalTo (Collections .singleton ("alice1" )));
193
+ });
194
+ }
195
+
196
+ @ Test public void gitChangelogSmokes () {
197
+ rr .then (r -> {
198
+ WorkflowJob p = r .jenkins .createProject (WorkflowJob .class , "p" );
199
+ p .setDefinition (new CpsFlowDefinition (
200
+ "node() {\n " +
201
+ " checkout(scm: [\n " +
202
+ " $class: 'GitSCM',\n " +
203
+ " branches: [[name: '*/master']],\n " +
204
+ " userRemoteConfigs: [[url: '" + sampleGitRepo .fileUrl () + "']]\n " +
205
+ " ])\n " +
206
+ "}" , true ));
207
+ sampleGitRepo .init (); // GitSampleRepoRule provides default user gits@mplereporule
208
+ sampleGitRepo .write ("foo" , "bar" );
209
+ sampleGitRepo .git ("add" , "foo" );
210
+ sampleGitRepo .git ("commit" , "-m" , "Initial commit" );
211
+ WorkflowRun b1 = r .buildAndAssertSuccess (p );
212
+ assertThat (b1 .getCulpritIds (), Matchers .equalTo (Collections .emptySet ()));
213
+ sampleGitRepo .write ("foo" , "bar1" );
214
+ sampleGitRepo .git ("add" , "foo" );
215
+ sampleGitRepo .git ("commit" , "-m" , "Second commit" );
216
+ WorkflowRun b2 = r .buildAndAssertSuccess (p );
217
+ assertThat (b2 .getCulpritIds (), Matchers .equalTo (Collections .singleton ("gits" )));
218
+ });
219
+ }
220
+
179
221
private static void assertPolling (WorkflowJob p , PollingResult .Change expectedChange ) {
180
222
assertEquals (expectedChange , p .poll (StreamTaskListener .fromStdout ()).change );
181
223
}
@@ -194,7 +236,7 @@ public ChangeLogSet<? extends ChangeLogSet.Entry> parse(Run build, RepositoryBro
194
236
}
195
237
};
196
238
}
197
- @ TestExtension ("scmParsesUmodifiedChangelogFile " )
239
+ @ TestExtension ("scmParsesUnmodifiedChangelogFile " )
198
240
public static class DescriptorImpl extends NullSCM .DescriptorImpl { }
199
241
}
200
242
0 commit comments