Exporting a Cloud Build Pipeline
In this tutorial, you will pull an example package that declares Kubernetes resources and two kpt functions. Then you will export a pipeline that runs the functions against the resources on Cloud Build. This tutorial takes about 5 minutes.
A kpt version
v0.32.0 or higher is required.
Before you begin
Unfamiliar with Cloud Build? Here is Cloud Build Quickstarts.
On your local machine, create an empty directory:
mkdir function-export-example cd function-export-example
All commands must be run at the root of this directory.
kpt pkg get to fetch source files of this tutorial:
# Fetch source files kpt pkg get https://github.com/GoogleContainerTools/kpt/package-examples/function-export example-package
Then you will get an
resources/resources.yaml: declares a
resources/constraints/: declares constraints used by the
functions.yaml: runs two functions declaratively:
gatekeeper-validateenforces constraints over all resources.
label-namespaceadds a label to all Namespaces.
Exporting a pipeline
kpt fn export example-package --workflow cloud-build --output cloudbuild.yaml
Running this command will generate a
cloudbuild.yaml like this:
steps: - name: gcr.io/kpt-dev/kpt:latest args: - fn - run - exmaple-package
Integrating with your existing pipeline
Now you can manually copy and paste the generated content into your existing build config file.
If you do not have one yet, you can simply put the file in the root of your project. It is fully functional.
If you want to see the diff after running kpt functions, append a
kpt pkg diff step to make your
cloudbuild.yaml look like this:
steps: - name: gcr.io/kpt-dev/kpt:latest args: - fn - run - example-package - name: gcr.io/kpt-dev/kpt:latest args: - pkg - diff - example-package - --diff-tool - git - --diff-tool-opts - "--no-pager diff"
Viewing the result on Cloud Build
Running this command will trigger a build:
gcloud builds submit .
Then you can view the result on Build History.
Try to remove the
owner: alice line in
Submit again, then view how the pipeline fails on Cloud Build.