1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-07 00:48:01 +01:00
Files
openshift-docs/modules/op-assembling-a-pipeline.adoc
2023-10-30 10:13:25 -04:00

126 lines
3.8 KiB
Plaintext

// This module is included in the following assembly:
//
// *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc
:_mod-docs-content-type: PROCEDURE
[id="assembling-a-pipeline_{context}"]
= Assembling a pipeline
A pipeline represents a CI/CD flow and is defined by the tasks to be executed. It is designed to be generic and reusable in multiple applications and environments.
A pipeline specifies how the tasks interact with each other and their order of execution using the `from` and `runAfter` parameters. It uses the `workspaces` field to specify one or more volumes that each task in the pipeline requires during execution.
In this section, you will create a pipeline that takes the source code of the application from GitHub, and then builds and deploys it on {product-title}.
The pipeline performs the following tasks for the back-end application `pipelines-vote-api` and front-end application `pipelines-vote-ui`:
* Clones the source code of the application from the Git repository by referring to the `git-url` and `git-revision` parameters.
* Builds the container image using the `buildah` cluster task.
* Pushes the image to the {product-registry} by referring to the `image` parameter.
* Deploys the new image on {product-title} by using the `apply-manifests` and `update-deployment` tasks.
[discrete]
.Procedure
. Copy the contents of the following sample pipeline YAML file and save it:
+
[source,yaml,subs="attributes+"]
----
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: build-and-deploy
spec:
workspaces:
- name: shared-workspace
params:
- name: deployment-name
type: string
description: name of the deployment to be patched
- name: git-url
type: string
description: url of the git repo for the code of deployment
- name: git-revision
type: string
description: revision to be used from repo of the code for deployment
default: "{pipelines-ver}"
- name: IMAGE
type: string
description: image to be built from the code
tasks:
- name: fetch-repository
taskRef:
name: git-clone
kind: ClusterTask
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: $(params.git-url)
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"
- name: revision
value: $(params.git-revision)
- name: build-image
taskRef:
name: buildah
kind: ClusterTask
params:
- name: IMAGE
value: $(params.IMAGE)
workspaces:
- name: source
workspace: shared-workspace
runAfter:
- fetch-repository
- name: apply-manifests
taskRef:
name: apply-manifests
workspaces:
- name: source
workspace: shared-workspace
runAfter:
- build-image
- name: update-deployment
taskRef:
name: update-deployment
params:
- name: deployment
value: $(params.deployment-name)
- name: IMAGE
value: $(params.IMAGE)
runAfter:
- apply-manifests
----
+
The pipeline definition abstracts away the specifics of the Git source repository and image registries. These details are added as `params` when a pipeline is triggered and executed.
. Create the pipeline:
+
----
$ oc create -f <pipeline-yaml-file-name.yaml>
----
+
Alternatively, you can also execute the YAML file directly from the Git repository:
+
[source,terminal,subs="attributes+"]
----
$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/01_pipeline/04_pipeline.yaml
----
. Use the `tkn pipeline list` command to verify that the pipeline is added to the application:
+
----
$ tkn pipeline list
----
+
The output verifies that the `build-and-deploy` pipeline was created:
+
----
NAME AGE LAST RUN STARTED DURATION STATUS
build-and-deploy 1 minute ago --- --- --- ---
----