Skip to content

Instantly share code, notes, and snippets.

@abayer
Created January 20, 2014 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abayer/8530507 to your computer and use it in GitHub Desktop.
Save abayer/8530507 to your computer and use it in GitHub Desktop.
Integration test for job-dsl-plugin context
package javaposse.jobdsl.plugin;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import static hudson.model.Result.SUCCESS;
import static javaposse.jobdsl.plugin.RemovedJobAction.IGNORE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ContextIntegrationTest {
@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();
@Test
public void testAllowEmptyArchive() throws Exception {
String emptyArchiveScript = "" +
"job {\n" +
" name('test-job')\n" +
" steps {\n" +
" shell(\"echo 'foo' > test\")\n" +
" }\n" +
" publishers {\n" +
" archiveArtifacts('test*')\n" +
" }\n" +
"}";
// setup
FreeStyleProject job = jenkinsRule.createFreeStyleProject("seed");
job.getBuildersList().add(new ExecuteDslScripts(new ExecuteDslScripts.ScriptLocation("true",
null, emptyArchiveScript), true, IGNORE));
// when
FreeStyleBuild freeStyleBuild = job.scheduleBuild2(0).get();
// then
assertEquals(SUCCESS, freeStyleBuild.getResult());
assertTrue(jenkinsRule.getInstance().getItem("test-job") instanceof FreeStyleProject);
}
}
@quidryan
Copy link

In groovy you can use triple quotes to make those big strings look a lot better. Then again shit goes sideways when using Groovy and JenkinsRule, so don't do it.

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