diff --git a/fetch/src/main/java/com/indix/gocd/s3fetch/Config.java b/fetch/src/main/java/com/indix/gocd/s3fetch/Config.java index 0d02dd3..8cc9878 100644 --- a/fetch/src/main/java/com/indix/gocd/s3fetch/Config.java +++ b/fetch/src/main/java/com/indix/gocd/s3fetch/Config.java @@ -15,6 +15,7 @@ public class Config { private final String source; private final String sourcePrefix; private final String destination; + private final String jobName; public String getMaterialType() { return materialType; @@ -52,6 +53,8 @@ public String getDestination() { return destination; } + public String getJobName() { return jobName; } + public Config(Map config) { materialType = getValue(config, MATERIAL_TYPE); repo = getValue(config, REPO); @@ -62,6 +65,7 @@ public Config(Map config) { source = getValue(config, SOURCE); sourcePrefix = getValue(config, SOURCE_PREFIX); destination = getValue(config, DESTINATION); + jobName = getValue(config, JOB_NAME); } private String escapeEnvironmentVariable(String value) { diff --git a/fetch/src/main/java/com/indix/gocd/s3fetch/FetchTask.java b/fetch/src/main/java/com/indix/gocd/s3fetch/FetchTask.java index efaa185..b2c2dec 100644 --- a/fetch/src/main/java/com/indix/gocd/s3fetch/FetchTask.java +++ b/fetch/src/main/java/com/indix/gocd/s3fetch/FetchTask.java @@ -145,6 +145,11 @@ private GoPluginApiResponse handleGetConfigRequest() { destination.put("required", false); config.put(Constants.DESTINATION, destination); + HashMap jobName = new HashMap(); + jobName.put("default-value", ""); + jobName.put("required", false); + config.put(Constants.JOB_NAME, jobName); + return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, config); } diff --git a/fetch/src/main/java/com/indix/gocd/s3fetch/PipelineFetchExecutor.java b/fetch/src/main/java/com/indix/gocd/s3fetch/PipelineFetchExecutor.java index b88f200..430fffd 100644 --- a/fetch/src/main/java/com/indix/gocd/s3fetch/PipelineFetchExecutor.java +++ b/fetch/src/main/java/com/indix/gocd/s3fetch/PipelineFetchExecutor.java @@ -22,7 +22,7 @@ protected String getArtifactsLocationTemplate(Config config, GoEnvironment env) String pipelineCounter = locatorParts[1]; String stage = locatorParts[2]; String stageCounter = locatorParts[3]; - String job = config.getJob(); + String job = config.getJobName(); return env.artifactsLocationTemplate(pipeline, stage, job, pipelineCounter, stageCounter); } @@ -33,8 +33,8 @@ public Map validate(Config config) { if (StringUtils.isBlank(config.getMaterial())) { errors.put(Constants.MATERIAL, Constants.REQUIRED_FIELD_MESSAGE); } - if (StringUtils.isBlank(config.getJob())) { - errors.put(Constants.JOB, Constants.REQUIRED_FIELD_MESSAGE); + if (StringUtils.isBlank(config.getJobName())) { + errors.put(Constants.JOB_NAME, Constants.REQUIRED_FIELD_MESSAGE); } return errors; } diff --git a/fetch/src/main/resources/views/task.template.html b/fetch/src/main/resources/views/task.template.html index 5343c83..f10d3f7 100644 --- a/fetch/src/main/resources/views/task.template.html +++ b/fetch/src/main/resources/views/task.template.html @@ -27,8 +27,8 @@
- - {{ GOINPUTNAME[Job].$error.server }} + + {{ GOINPUTNAME[JobName].$error.server }}
@@ -85,6 +85,7 @@ this.Repo = null; this.Package = null; this.Material = null; + this.JobName = null; this.clearStageFields(); }; }); diff --git a/fetch/src/test/java/com/indix/gocd/s3fetch/PipelineFetchExecutorTest.java b/fetch/src/test/java/com/indix/gocd/s3fetch/PipelineFetchExecutorTest.java index 300cd96..e4dc7d5 100644 --- a/fetch/src/test/java/com/indix/gocd/s3fetch/PipelineFetchExecutorTest.java +++ b/fetch/src/test/java/com/indix/gocd/s3fetch/PipelineFetchExecutorTest.java @@ -43,7 +43,7 @@ public void setUp() throws Exception { config = new Config(Maps.builder() .with(Constants.MATERIAL_TYPE, Maps.builder().with("value", "Pipeline").build()) .with(Constants.MATERIAL, Maps.builder().with("value", "mymaterial").build()) - .with(Constants.JOB, Maps.builder().with("value", "job").build()) + .with(Constants.JOB_NAME, Maps.builder().with("value", "job").build()) .with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build()) .build()); @@ -105,7 +105,7 @@ public void shouldBeAbleToHandleTaskConfigEntriesWithDashesInTheName() { config = new Config(Maps.builder() .with(Constants.MATERIAL, Maps.builder().with("value", "my-material").build()) - .with(Constants.JOB, Maps.builder().with("value", "job").build()) + .with(Constants.JOB_NAME, Maps.builder().with("value", "job").build()) .with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build()) .build()); TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables)); @@ -125,7 +125,7 @@ public void shouldBeAbleToHandleTaskConfigEntriesWithPeriodsInTheName() { config = new Config(Maps.builder() .with(Constants.MATERIAL, Maps.builder().with("value", "my.material").build()) - .with(Constants.JOB, Maps.builder().with("value", "job").build()) + .with(Constants.JOB_NAME, Maps.builder().with("value", "job").build()) .with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build()) .build()); TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables)); @@ -145,7 +145,7 @@ public void shouldBeAbleToHandleTaskConfigEntriesWithSpecialCharactersInTheName( config = new Config(Maps.builder() .with(Constants.MATERIAL, Maps.builder().with("value", "my`~!@#$%^&*()-+=[{]}\\|;:'\",<.>/?material").build()) - .with(Constants.JOB, Maps.builder().with("value", "job").build()) + .with(Constants.JOB_NAME, Maps.builder().with("value", "job").build()) .with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build()) .build()); TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables)); diff --git a/utils/src/main/java/com/indix/gocd/utils/Constants.java b/utils/src/main/java/com/indix/gocd/utils/Constants.java index 25ecd82..eba60b7 100644 --- a/utils/src/main/java/com/indix/gocd/utils/Constants.java +++ b/utils/src/main/java/com/indix/gocd/utils/Constants.java @@ -33,6 +33,7 @@ public class Constants { public static final String SOURCE = "Source"; public static final String SOURCE_PREFIX = "SourcePrefix"; public static final String DESTINATION = "Destination"; + public static final String JOB_NAME = "JobName"; public static final String REQUIRED_FIELD_MESSAGE = "This field is required"; }