-
Notifications
You must be signed in to change notification settings - Fork 4
Working with codestream pipeline input and outputs
To provide better definition flow and reusability, we added several ways you can handle your inputs and outputs. Here's an example:
Input extractedInput = new Input("globalPipelineInput", "defaultValue")
return Pipeline.builder()
.name("test")
.inputs([
"inputName": "defaultValue"
])
.outputs([
"outputName": Output.taskOutputReference("stage-1", "task-1", "something")
])
.stages([
Stage.builder()
.name("stage-1")
.tasks([
JenkinsTask.builder()
.name("task-1")
.job("job-1")
.inputs([
new Input("localInput", "defaultValue"),
new Input("pipelineInput", "defaultValue", true),
new Input("pipelineInput2", extractedInput)
])
.outputs([
new Output("somethingElse", "pipelineOutput")
])
.build()
])
.build()
])
.build()
Pipeline.inputs
and Pipeline.outputs
are traditional, global, basic definitions of inputs and outputs as you see them in Codestream. In the above example Output.taskOutputReference("stage-1", "task-1", "output")
will be evaluated to ${stage-1.task-1.output.something}
In the task-1
definition, we have examples for 3 different Input definitions:
-
new Input("localInput", "defaultValue")
- this is a basic task input. -
new Input("pipelineInput", "defaultValue", true)
- this defines a task input and exposes it as global parameter. This is the same as havingPipeline.inputs
with namepipelineInput
and default value ofdefaultValue
and a task input with namepipelineInput
and value${input.pipelineInput}
(reference to the global input) -
new Input("pipelineInput2", extractedInput)
- similar to the above. This is the same as havingPipeline.inputs
with nameglobalPipelineInput
and default value ofdefaultValue
and a task input with namepipelineInput2
and value${input.globalPipelineInput}
For outputs we have new Output("localKey", "globalKey")
- This is the same as having Pipeline.outputs
with name pipelineOutput
and output reference of ${stage-1.task-1.output.somethingElse}
That allows us to define global inputs and outputs as we go writing the code.
Sometimes we need to refer to an input outside of a task input context. For type safety, use com.vmware.devops.model.codestream.Input#globalInputReference()
. Input.globalInputReference("key")
produces ${input.key}
. This can also be used on instanced object:
Input input = new Input("key", "value")
String reference = input.globalInputReference()
This will produce the same reference of ${input.key}