- How do I create a new Pipeline?
- How do I make a Task?
- How do I make Resources?
- How do I run a Pipeline?
- How do I run a Task on its own?
- Create or copy Task definitions for the tasks you’d like to run. Some can be generic and reused (e.g. building with Kaniko) and others will be specific to your project (e.g. running your particular set of unit tests).
- Create a
PipelineParams
definition which includes parameters such as what repos to run against, where to store results, etc. - Create a
Pipeline
which expresses the Tasks you would like to run and what Resources the Tasks need. UsepassedConstraints
to express the order theTasks
should run in.
See the example guestbook Pipeline and the example kritis Pipeline.
When you need to execute Tasks
in a particular order, it will likely be because they
are operating over the same Resources
(e.g. your unit test task must run first against
your git repo, then you build an image from that repo, then you run integration tests
against that image).
We express this ordering by adding passedConstraints
on Resources
that our Tasks
need.
- The (optional)
passedConstraints
key on aninput source
defines a set of previous task names. - When the
passedConstraints
key is specified on an input source, only the version of the resource that passed through the defined list of tasks is used. - The
passedConstraints
allows forTasks
to fan in and fan out, and ordering can be expressed explicitly using this key since a task needing a resource from a another task would have to run after.
To create a Task, you must:
- Define parameters (i.e. string inputs) for your
Task
- Define the inputs and outputs of the
Task
asResources
- Create a
Step
for each action you want to take in theTask
Steps
are images which comply with the image contract.
Each container image used as a step in a Task
must comply with a specific
contract.
For example, in the following Task the images, gcr.io/cloud-builders/gcloud
and gcr.io/cloud-builders/docker
run as steps:
spec:
buildSpec:
steps:
- image: gcr.io/cloud-builders/gcloud
command: ['gcloud']
...
- image: gcr.io/cloud-builders/docker
command: ['docker']
...
You can also provide args
to the image's command
:
steps:
- image: ubuntu
command: ['/bin/bash']
args: ['-c', 'echo hello $FOO']
env:
- name: 'FOO'
value: 'world'
/workspace
: If an input is provided, the default working directory will be/workspace
and this will be shared acrosssteps
(note that in #123 we will add supprots for multiple input workspaces)/builder/home
: This volume is exposed to steps via$HOME
.- Credentials attached to the Build's service account may be exposed as Git or Docker credentials as outlined in the auth docs.
Tasks support templating using values from all inputs
and outputs
.
For example Resources
can be referenced in a Task
spec like this,
where NAME
is the Resource Name and KEY
is one of name
, url
, type
or
revision
:
${inputs.resources.NAME.KEY}
- To run your
Pipeline
, create a newPipelineRun
which links yourPipeline
to thePipelineParams
it will run with. - Creation of a
PipelineRun
will trigger the creation ofTaskRuns
for eachTask
in your pipeline.
- To run a
Task
, create a newTaskRun
which defines all inputs, outputs that theTask
needs to run. - The
TaskRun
will also serve as a record of the history of the invocations of theTask
.
See the example TaskRun.
Git resource represents a git repository, that containes the source code to be built by the pipeline. Adding the git resource as an input to a task will clone this repository and allow the task to perform the required actions on the contents of the repo.
Use the following example to understand the syntax and strucutre of a Git Resource
-
Create a git resource using the
PipelineResource
CRDapiVersion: pipeline.knative.dev/v1alpha1 kind: PipelineResource metadata: name: wizzbang-git namespace: default spec: type: git params: - name: url value: github.com/wizzbangcorp/wizzbang - name: Revision value: master
Params that can be added are the following:
- URL: represents the location of the git repository
- Revision: Git revision (branch, tag, commit SHA or ref) to clone. If no revision is specified, the resource will default to
latest
frommaster
-
Use the defined git resource in a
Task
definition:apiVersion: pipeline.knative.dev/v1alpha1 kind: Task metadata: name: build-push-task namespace: default spec: inputs: resources: - name: wizzbang-git type: git params: - name: pathToDockerfile value: string outputs: resources: - name: builtImage buildSpec: steps: - name: build-and-push image: gcr.io/my-repo/my-imageg args: - --repo=${inputs.resources.wizzbang-git.url}
-
And finally set the version in the
TaskRun
definition:apiVersion: pipeline.knative.dev/v1alpha1 kind: TaskRun metadata: name: build-push-task-run namespace: default spec: taskRef: name: build-push-task inputs: resourcesVersion: - resourceRef: name: wizzbang-git version: HEAD outputs: artifacts: - name: builtImage type: image