101 lines
3.6 KiB
YAML
101 lines
3.6 KiB
YAML
apiVersion: tekton.dev/v1beta1
|
|
kind: Task
|
|
metadata:
|
|
name: git-clone
|
|
spec:
|
|
workspaces:
|
|
- name: output
|
|
description: The git repo will be cloned onto the volume backing this workspace
|
|
params:
|
|
- name: url
|
|
description: git url to clone
|
|
type: string
|
|
default: http://git-ui.lan/chaos/kubernetes.git
|
|
- name: revision
|
|
description: git revision to checkout (branch, tag, sha, ref…)
|
|
type: string
|
|
default: master
|
|
- name: refspec
|
|
description: (optional) git refspec to fetch before checking out revision
|
|
default: ""
|
|
- name: submodules
|
|
description: defines if the resource should initialize and fetch the submodules
|
|
type: string
|
|
default: "true"
|
|
- name: depth
|
|
description: performs a shallow clone where only the most recent commit(s) will be fetched
|
|
type: string
|
|
default: "1"
|
|
- name: sslVerify
|
|
description: defines if http.sslVerify should be set to true or false in the global git config
|
|
type: string
|
|
default: "true"
|
|
- name: subdirectory
|
|
description: subdirectory inside the "output" workspace to clone the git repo into
|
|
type: string
|
|
default: ""
|
|
- name: deleteExisting
|
|
description: clean out the contents of the repo's destination directory (if it already exists) before trying to clone the repo there
|
|
type: string
|
|
default: "true"
|
|
- name: httpProxy
|
|
description: git HTTP proxy server for non-SSL requests
|
|
type: string
|
|
default: ""
|
|
- name: httpsProxy
|
|
description: git HTTPS proxy server for SSL requests
|
|
type: string
|
|
default: ""
|
|
- name: noProxy
|
|
description: git no proxy - opt out of proxying HTTP/HTTPS requests
|
|
type: string
|
|
default: ""
|
|
results:
|
|
- name: commit
|
|
description: The precise commit SHA that was fetched by this Task
|
|
steps:
|
|
- name: clone
|
|
image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.30.2
|
|
script: |
|
|
CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)"
|
|
|
|
cleandir() {
|
|
# Delete any existing contents of the repo directory if it exists.
|
|
#
|
|
# We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/"
|
|
# or the root of a mounted volume.
|
|
if [[ -d "$CHECKOUT_DIR" ]] ; then
|
|
# Delete non-hidden files and directories
|
|
rm -rf "$CHECKOUT_DIR"/*
|
|
# Delete files and directories starting with . but excluding ..
|
|
rm -rf "$CHECKOUT_DIR"/.[!.]*
|
|
# Delete files and directories starting with .. plus any other character
|
|
rm -rf "$CHECKOUT_DIR"/..?*
|
|
fi
|
|
}
|
|
|
|
if [[ "$(params.deleteExisting)" == "true" ]] ; then
|
|
cleandir
|
|
fi
|
|
|
|
test -z "$(params.httpProxy)" || export HTTP_PROXY=$(params.httpProxy)
|
|
test -z "$(params.httpsProxy)" || export HTTPS_PROXY=$(params.httpsProxy)
|
|
test -z "$(params.noProxy)" || export NO_PROXY=$(params.noProxy)
|
|
|
|
/ko-app/git-init \
|
|
-url "$(params.url)" \
|
|
-revision "$(params.revision)" \
|
|
-refspec "$(params.refspec)" \
|
|
-path "$CHECKOUT_DIR" \
|
|
-sslVerify="$(params.sslVerify)" \
|
|
-submodules="$(params.submodules)" \
|
|
-depth "$(params.depth)"
|
|
cd "$CHECKOUT_DIR"
|
|
RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')"
|
|
EXIT_CODE="$?"
|
|
if [ "$EXIT_CODE" != 0 ]
|
|
then
|
|
exit $EXIT_CODE
|
|
fi
|
|
# Make sure we don't add a trailing newline to the result!
|
|
echo -n "$RESULT_SHA" > $(results.commit.path) |