public final String toGroovy(boolean indent) { Descriptor d = getDescriptor(); if (d instanceof DirectiveDescriptor) { if (indent) { return ((DirectiveDescriptor) d).toIndentedGroovy(this); } else { return ((DirectiveDescriptor) d).toGroovy(this); } } else { return "// Not a valid descriptor"; } } }
public String getName() { // TODO: This could probably be easier, but I wanted to use a localized string and couldn't think of anything better. if (this == STEPS) { return Messages.StageDirective_Steps_name(); } else if (this == PARALLEL) { return Messages.StageDirective_Parallel_name(); } else if (this == STAGES) { return Messages.StageDirective_Stages_name(); } else { return "(unknown)"; } } }
public String getLibHelp(String field) { return "/descriptor/" + getId() + "/help/" + field; } }
@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 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 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 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 simpleInput() throws Exception { InputDirective input = new InputDirective("hello"); assertGenerateDirective(input, "input {\n" + " message 'hello'\n" + "}"); }
@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" + "}"); }
public String getEnvHelp(String field) { return "/descriptor/" + getId() + "/help/" + field; } }
@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 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 agentNone() throws Exception { AgentDirective agent = new AgentDirective(new None()); assertGenerateDirective(agent, "agent none"); }
@Test public void whenChangelog() throws Exception { WhenDirective when = new WhenDirective(new ChangeLogConditional("some-pattern"), false); assertGenerateDirective(when, "when {\n" + " changelog 'some-pattern'\n" + "}"); }
@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 whenChangeset() throws Exception { WhenDirective when = new WhenDirective(new ChangeSetConditional("some/file/in/changeset"), false); assertGenerateDirective(when, "when {\n" + " changeset 'some/file/in/changeset'\n" + "}"); }
@Test public void agentAny() throws Exception { AgentDirective agent = new AgentDirective(new Any()); assertGenerateDirective(agent, "agent any"); }
@Test public void whenAllOfEmpty() throws Exception { WhenDirective when = new WhenDirective(new AllOfConditional(null), false); assertGenerateDirective(when, "when {\n" + " allOf {\n" + " }\n" + "}"); }