Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active January 4, 2022 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmouel/680e8b21dec3a917fcc0ca5825bf2dbb to your computer and use it in GitHub Desktop.
Save chmouel/680e8b21dec3a917fcc0ca5825bf2dbb to your computer and use it in GitHub Desktop.
Tekton Pipelines as Code demo

This uses a GitHub Enteprise instance but the same apply to a Public GitHub you just need to use https://github.com/

Create a Repository

Add PAC GitHub app into it:

https://ghe.pipelines.devcluster.openshift.com/github-apps/pipelines-as-code

Checkout repository

git clone git@ghe.pipelines.devcluster.openshift.com:pac/demo.git /tmp/demo
cd /tmp/demo

Create a new project

oc new-project demo

Create a PAC repository

tkn pac repo create

Inspect generated .tekton template

vi .tekton/pull_request.yaml

Add this into the noop-step before the exit 0

test -e LICENSE || exit 1

Commit and create a push

git checkout -b tektonci
git add .tekton
git commit -m "Add tekton ci 🐱"
git push -u origin tektonci

Create the Pull Request

https://ghe.pipelines.devcluster.openshift.com/pac/demo/compare/tektonci?expand=1

Wait for it to create the pipelinerun and watch it fail

watch -n2 tkn pr ls  
tkn pr logs -Lf

Inspect status with tkn pac

tkn pac repo ls
tkn pac repo describe  

Create a LICENSE file, commit and push it

echo "Be kind and helpful license" > LICENSE
git add LICENSE
git commit -m "Add LICENSE" LICENSE
git push

Show tkn pac repo describe

tkn pac repo describe  

Create a push pipelinerun

tkn pac repo new --event-type push --branch main \
    --name demo-push --namespace demo \
    --url https://ghe.pipelines.devcluster.openshift.com/pac/demo  

Inspect it

  • vi .tekton/push.yaml
  • add a “echo Success on PUSH” into the noop-task

Commit and push it

git add . && git commit -asm "Add push file" && git push

Wait that it succeed

watch -n2 tkn pr ls  

Merge it

https://ghe.pipelines.devcluster.openshift.com/pac/demo/pull/1

Wait that the pipelinerun push appears

watch -n2 tkn pr ls --label=tekton.dev/pipeline-ascode-event-type=push

And tkn pr logs it :

tkn pr logs -L

Cleanup

oc delete project demo && \
cd && \
rm -rf /tmp/demo && \
curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  -H "Authorization: token $(git config --get github.ghe-token)" \
  https://api.ghe.pipelines.devcluster.openshift.com/repos/pac/demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment