Maven Java jar containing the class - ExecuteDslScripts : where ?

5 views
Skip to first unread message

Charles Moulliard

unread,
Dec 15, 2020, 1:01:42 PM12/15/20
to job-dsl-plugin
Hi,

Where can we get the java jar file containing the following class "ExecuteDslScripts" when we create Java Test cases ?

public class HelloGroovyCommandAndFreeStyleJobTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();

    @Test
    public void sayHelloFreeStyleJob() throws Exception {
        FreeStyleProject project = j.createFreeStyleProject();
        project.getBuildersList().add(new ExecuteDslScripts());

Cheers

Charles

Charles Moulliard

unread,
Dec 16, 2020, 11:09:16 AM12/16/20
to job-dsl-plugin
I found the solution

public class MavenJobDSLTest {
    @Rule
    public JenkinsRule j = new JenkinsRule();

    @Test
    public void useMavenDSLGroovyFileAsJob() throws Exception {
        FreeStyleProject p = j.createFreeStyleProject();
        p.scheduleBuild2(0).get(); // run a build to create a workspace
        p.getSomeWorkspace().child("mavenProject/mavenJob.groovy").copyFrom(getClass().getResourceAsStream("/mavenJob.groovy"));

        ExecuteDslScripts e = new ExecuteDslScripts();
        e.setTargets("mavenProject/mavenJob.groovy");
        p.getBuildersList().add(e);

        // Assert if build succeeded, if the Script executed includes the echo message
        FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0).get());
        b.keepLog();

        assertEquals(2, b.number);
        assertEquals("#2",b.getDisplayName());
        assertEquals("SUCCESS",b.getResult().toString());

        // Check if the FreeStyleProject build reported that it generated the job: say-hello-world
        ArrayList LogResult = (ArrayList) b.getLog(100);
        //LogResult.forEach((s) -> System.out.println(s));
        assertTrue(b.getLog(100).stream().anyMatch(str -> str.contains("GeneratedJob{name='say-hello-world'}")));

        // Get the FreeStyleProject containing the Job DSL steps to be executed - Say Hello World
        FreeStyleProject freeStyleProjectGeneratedJob = (FreeStyleProject) j.jenkins.getItem("say-hello-world");
        FreeStyleBuild b2 =  freeStyleProjectGeneratedJob.scheduleBuild2(0).get();

        assertEquals(1, b2.number);
        assertEquals("#1",b2.getDisplayName());
        assertEquals("SUCCESS",b2.getResult().toString());

        // Check if the FreeStyleProject build reported that it generated the job: say-hello-world
        assertTrue(b2.getLog(100).stream().anyMatch(str -> str.contains("Say Hello World !")));




Reply all
Reply to author
Forward
0 new messages