mirror of
https://github.com/tektoncd/catalog.git
synced 2024-12-02 06:52:15 +00:00
d12e690595
The git-clone example only demonstrated the very simplest of behaviour and didn't provide much in the way of instruction on using its features. This PR adds examples for cloning a branch, cloning a specific commit, and cloning tags. Each example includes clear description of its purpose and the features it demonstrates. I've removed the inline git-clone example from the README because it's really long and the README needs to serve the purpose of documenting multiple Tasks (git-clone as well as git-batch-merge, and any future Tasks we add as well). Rather than bloat the README with many examples which can go stale if we modify git-clone's behaviour I've simply linked to the new example files.
88 lines
2.6 KiB
YAML
88 lines
2.6 KiB
YAML
apiVersion: tekton.dev/v1beta1
|
|
kind: Pipeline
|
|
metadata:
|
|
name: checking-out-a-revision
|
|
spec:
|
|
description: |
|
|
checking-out-a-revision takes a git repository and a commit SHA
|
|
and validates that cloning the revision succeeds. This is an example
|
|
Pipeline demonstrating the following:
|
|
- Using the git-clone catalog Task to clone a specific commit
|
|
- Passing a cloned repo to subsequent Tasks using a Workspace.
|
|
- Ordering Tasks in a Pipeline using "runAfter" so that
|
|
git-clone completes before we try to read from the Workspace.
|
|
- Using a volumeClaimTemplate Volume as a Workspace.
|
|
- Avoiding hard-coded paths by using a Workspace's path
|
|
variable instead.
|
|
params:
|
|
- name: repo-url
|
|
type: string
|
|
description: The git repository URL to clone from.
|
|
- name: commit
|
|
type: string
|
|
description: The git commit to fetch.
|
|
workspaces:
|
|
- name: shared-data
|
|
description: |
|
|
This workspace will receive the cloned git repo and be passed
|
|
to the next Task for the commit to be checked.
|
|
tasks:
|
|
- name: fetch-repo
|
|
taskRef:
|
|
name: git-clone
|
|
workspaces:
|
|
- name: output
|
|
workspace: shared-data
|
|
params:
|
|
- name: url
|
|
value: $(params.repo-url)
|
|
- name: revision
|
|
value: $(params.commit)
|
|
- name: compare-received-commit-to-expected
|
|
runAfter: ["fetch-repo"] # Wait until the clone is done before reading the readme.
|
|
params:
|
|
- name: expected-commit
|
|
value: $(params.commit)
|
|
workspaces:
|
|
- name: source
|
|
workspace: shared-data
|
|
taskSpec:
|
|
params:
|
|
- name: expected-commit
|
|
workspaces:
|
|
- name: source
|
|
steps:
|
|
- image: alpine/git:v2.24.3
|
|
script: |
|
|
#!/usr/bin/env sh
|
|
cd $(workspaces.source.path)
|
|
receivedCommit=$(git rev-parse HEAD)
|
|
if [ $receivedCommit != $(params.expected-commit) ]; then
|
|
echo "Expected commit $(params.expected-commit) but received $receivedCommit."
|
|
exit 1
|
|
else
|
|
echo "Received commit $receivedCommit as expected."
|
|
fi
|
|
---
|
|
apiVersion: tekton.dev/v1beta1
|
|
kind: PipelineRun
|
|
metadata:
|
|
generateName: git-clone-checking-out-a-commit-
|
|
spec:
|
|
pipelineRef:
|
|
name: checking-out-a-revision
|
|
workspaces:
|
|
- name: shared-data
|
|
volumeClaimTemplate:
|
|
spec:
|
|
accessModes:
|
|
- ReadWriteOnce
|
|
resources:
|
|
requests:
|
|
storage: 500Mi
|
|
params:
|
|
- name: repo-url
|
|
value: https://github.com/tektoncd/pipeline.git
|
|
- name: commit
|
|
value: 301b41380e95382a18b391c2165fa3a6a3de93b0 # Tekton Pipeline's first ever commit!
|