本例是第一步,使用 git 下载代码,并且 提取 commitid
既然是从git下载代码,那么首先就要创建 git resource
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: tektongolang-git
namespace: lizhe
spec:
type: git
params:
- name: revision
value: master
- name: url
value: https://github.com/zl86790/tektongolang.git
然后我们创建 git 仓库的权限
apiVersion: v1
kind: Secret
metadata:
name: git-secret
namespace: lizhe
annotations:
tekton.dev/git-0: https://github.com # Described below
type: kubernetes.io/basic-auth
stringData:
username: <cleartext username>
password: <cleartext password>
因为下面我们会使用一个私有docker镜像,所以这里再创建一个docker权限
kubectl create secret docker-registry docker-secret -n lizhe \
--docker-server=https://index.docker.io/v1/ \
--docker-username=<your-name> \
--docker-password=<your-pword> \
--docker-email=<your-email>
创建一个 service account,并且附加上刚刚创建的 git-secret 和docker-secret
apiVersion: v1
kind: ServiceAccount
metadata:
name: build-bot-sa
namespace: lizhe
secrets:
- name: git-secret
- name: docker-secret
然后我们创建一个 getcommitid 的 task
这个task使用的 image 是 getcommitid.sh
touch /$1/commitid.txt
git -C /$1 rev-parse HEAD > /$1/commitid.txt
ls /$1
cat /$1/commitid.txt
创建task
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: get-commitid
namespace: lizhe
spec:
resources:
inputs:
- name: git-source
type: git
steps:
- name: get-commitid
image: libaibai/gitcid
env:
- name: "DOCKER_CONFIG"
value: "/tekton/home/.docker/"
command: ["/bin/bash", "-c", "/getcommitid.sh /workspace/git-source"]
尝试启动这个task