Files
stage-infra/Tekton/tasks/deploy-app.yaml

54 lines
2.0 KiB
YAML

---
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: deploy-yaml-file
namespace: tekton-pipeline-1
spec:
params:
- name: yaml-location
default: infra/deploy-example.yaml
- name: command
default: apply
- name: deploy-name
default: ""
- name: deploy-version
default: ""
workspaces:
- name: source
mountpath: /source
results:
- name: state
description: state of the next github update
- name: description
description: description of the next github update
steps:
- name: deploy-new-app
image: lachlanevenson/k8s-kubectl
script: |
sed -i -e 's;DEPLOY_NAME;$(params.deploy-name);g' /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
printf "failure" > /tekton/results/state
printf "replacing deploy name in yaml file failed, please check if the yaml file is in the correct location ($(params.yaml-location))" > /tekton/results/description
exit 0
fi
sed -i -e 's;DEPLOY_VERSION;$(params.deploy-version);g' /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
printf "failure" > /tekton/results/state
printf "replacing deploy version in yaml file failed, please check if the yaml file is in the correct location ($(params.yaml-location))" > /tekton/results/description
exit 0
fi
kubectl delete -f /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
echo "nothting to worry abt, just means its been manually deleted before this was run"
fi
kubectl $(params.command) -f /source/$(params.yaml-location)
if [ "$?" != 0 ]; then
printf "failure" > /tekton/results/state
printf "failure applying yaml file to cluster ($(params.yaml-location))" > /tekton/results/description
else
printf "success" > /tekton/results/state
printf "deployed the yaml files to the cluster"
fi
exit 0