@Test public void post() throws Exception { PostDirective post = new PostDirective(Arrays.asList("always", "unstable")); assertGenerateDirective(post, "post {\n" + " always {\n" + " // One or more steps need to be included within each condition's block.\n" + " }\n" + " unstable {\n" + " // One or more steps need to be included within each condition's block.\n" + " }\n" + "}"); }
@Test public void simpleStage() throws Exception { StageDirective stage = new StageDirective(Collections.emptyList(), "bob", StageDirective.StageContentType.STEPS); assertGenerateDirective(stage, "stage('bob') {\n" + " steps {\n" + " // One or more steps need to be included within the steps block.\n" + " }\n" + "}"); }
@Test public void simpleParallelStage() throws Exception { StageDirective stage = new StageDirective(Collections.emptyList(), "bob", StageDirective.StageContentType.PARALLEL); assertGenerateDirective(stage, "stage('bob') {\n" + " parallel {\n" + " // One or more stages need to be included within the parallel block.\n" + " }\n" + "}"); }
@Test public void simpleInput() throws Exception { InputDirective input = new InputDirective("hello"); assertGenerateDirective(input, "input {\n" + " message 'hello'\n" + "}"); }
@Test public void triggersSingle() throws Exception { List<Trigger> t = new ArrayList<>(); t.add(new TimerTrigger("@daily")); TriggersDirective triggers = new TriggersDirective(t); assertGenerateDirective(triggers, "triggers {\n" + " cron '@daily'\n" + "}"); }
@Test public void triggersMultiple() throws Exception { List<Trigger> t = new ArrayList<>(); t.add(new TimerTrigger("@daily")); t.add(new SCMTrigger("@hourly")); TriggersDirective triggers = new TriggersDirective(t); assertGenerateDirective(triggers, "triggers {\n" + " cron '@daily'\n" + " pollSCM '@hourly'\n" + "}"); }
@Issue("JENKINS-46809") @Test public void simpleSequentialStage() throws Exception { StageDirective stage = new StageDirective(Collections.emptyList(), "bob", StageDirective.StageContentType.STAGES); assertGenerateDirective(stage, "stage('bob') {\n" + " stages {\n" + " // One or more stages need to be included within the stages block.\n" + " }\n" + "}"); }
@Test public void environment() throws Exception { List<EnvironmentDirective.NameAndValue> envList = new ArrayList<>(); envList.add(new EnvironmentDirective.NameAndValue("BOB", "steve")); envList.add(new EnvironmentDirective.NameAndValue("WHAT", "${BOB} says hi")); EnvironmentDirective env = new EnvironmentDirective(envList); assertGenerateDirective(env, "environment {\n" + " BOB = \"steve\"\n" + " WHAT = \"${BOB} says hi\"\n" + "}"); }
@Test public void parametersSingle() throws Exception { List<ParameterDefinition> p = new ArrayList<>(); p.add(new StringParameterDefinition("SOME_STRING", "some default", "Hey, a description with a ' in it.")); ParametersDirective params = new ParametersDirective(p); assertGenerateDirective(params, "parameters {\n" + " string defaultValue: 'some default', description: 'Hey, a description with a \\' in it.', name: 'SOME_STRING'" + trimParamOrEmpty() + "\n" + "}"); }
@Test public void libraries() throws Exception { List<LibrariesDirective.NameAndVersion> libList = new ArrayList<>(); libList.add(new LibrariesDirective.NameAndVersion("first-lib")); LibrariesDirective.NameAndVersion second = new LibrariesDirective.NameAndVersion("second-lib"); second.setVersion("master"); libList.add(second); LibrariesDirective libs = new LibrariesDirective(libList); assertGenerateDirective(libs, "libraries {\n" + " lib('first-lib')\n" + " lib('second-lib@master')\n" + "}"); }
@Test public void tools() throws Exception { ToolsDirective tools = new ToolsDirective(Collections.singletonList(new ToolsDirective.SymbolAndName("maven::::apache-maven-3.0.1"))); assertGenerateDirective(tools, "tools {\n" + " maven 'apache-maven-3.0.1'\n" + "}"); }
@Test public void agentLabel() throws Exception { AgentDirective agent = new AgentDirective(new Label("some-label")); assertGenerateDirective(agent, "agent {\n" + " label 'some-label'\n" + "}"); }
@Test public void whenBranch() throws Exception { WhenDirective when = new WhenDirective(new BranchConditional("some-pattern"), true); assertGenerateDirective(when, "when {\n" + " branch 'some-pattern'\n" + " beforeAgent true\n" + "}"); }
@Test public void simpleAgentDockerfile() throws Exception { AgentDirective agent = new AgentDirective(new DockerPipelineFromDockerfile()); assertGenerateDirective(agent, "agent {\n" + " dockerfile true\n" + "}"); }
@Test public void whenEnvironment() throws Exception { WhenDirective when = new WhenDirective(new EnvironmentConditional("SOME_VAR", "some value"), false); assertGenerateDirective(when, "when {\n" + " environment name: 'SOME_VAR', value: 'some value'\n" + "}"); }
@Test public void agentNone() throws Exception { AgentDirective agent = new AgentDirective(new None()); assertGenerateDirective(agent, "agent none"); }
@Test public void simpleAgentDocker() throws Exception { AgentDirective agent = new AgentDirective(new DockerPipeline("some-image")); assertGenerateDirective(agent, "agent {\n" + " docker 'some-image'\n" + "}"); }
@Test public void agentAny() throws Exception { AgentDirective agent = new AgentDirective(new Any()); assertGenerateDirective(agent, "agent any"); }
@Issue("JENKINS-51932") @Test public void whenIsRestartedRun() throws Exception { WhenDirective when = new WhenDirective(new IsRestartedRunConditional(), false); assertGenerateDirective(when, "when {\n" + " isRestartedRun()\n" + "}"); }
@Test public void whenNot() throws Exception { WhenDirective when = new WhenDirective(new NotConditional(new BranchConditional("some-bad-branch")), false); assertGenerateDirective(when, "when {\n" + " not {\n" + " branch 'some-bad-branch'\n" + " }\n" + "}"); }