Create Git Tag#
Objectives#
- Add
create-git-tag
task to PipelineRun. - Define parameters, workspaces, and tasks within the PipelineRun for building and deploying your application.
Key Results#
- Successfully create and execute the Tekton PipelineRun using the defined
.tekton/main.yaml
file, enabling automated CI/CD processes for your application.
Tutorial#
Create PipelineRun with Create Git Tag Task#
You have already created a PipelineRun in the previous tutorial. Let's now add another task 'create-git-tag` to it.
- Open up the PipelineRun file you created in the previous tutorial.
-
Now edit the file, so the YAML becomes like the one given below.
apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: git-clone annotations: pipelinesascode.tekton.dev/on-event: "[pull_request]" # Trigger the pipelineRun on pull_request events on branch main pipelinesascode.tekton.dev/on-target-branch: "main" pipelinesascode.tekton.dev/task: "[git-clone]" # The tasks will be fetched from Tekton Hub. We can also provide direct links to yaml files pipelinesascode.tekton.dev/max-keep-runs: "2" # Only remain 2 latest pipelineRuns on SAAP spec: params: - name: repo_url value: "{{body.repository.ssh_url}}" # Place your repo SSH URL - name: git_revision value: "{{revision}}" # Dynamic variable to fetch branch name of the push event on your repo - name: repo_name value: "{{repo_name}}" # Dynamic varaible to fetch repo name - name: repo_path value: "review-api" # Dynamic varaible for app name - name: git_branch value: "{{source_branch}}" - name: pull_request_number value: "{{pull_request_number}}" - name: organization value: "{{body.organization.login}}" pipelineSpec: # Define what parameters will be used for pipeline params: - name: repo_url - name: git_revision - name: repo_name - name: repo_path - name: pull_request_number - name: organization - name: git_branch workspaces: # Mention what workspaces will be used by this pipeline to store data and used by data transferring between tasks - name: source - name: ssh-directory tasks: # Mention what tasks will be used by this pipeline - name: fetch-repository #Name what you want to call the task taskRef: name: git-clone # Name of tasks mentioned in tekton-catalog kind: ClusterTask workspaces: # Mention what workspaces will be used by this task - name: output workspace: source - name: ssh-directory workspace: ssh-directory params: # Parameters will be used by this task - name: depth value: "0" - name: url value: $(params.repo_url) - name: revision value: $(params.git_revision) workspaces: # Mention Workspaces configuration - name: source volumeClaimTemplate: spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi - name: ssh-directory # Using ssh-directory workspace for our task to have better security secret: secretName: git-ssh-creds # Created this secret earlier - name: repo-token secret: secretName: git-pat-creds
Notice that we added another value to the
pipelinesascode.tekton.dev/task
annotation. The annotation is used by pipeline as code resolver to fetch tasks defined remotely. To explore stakater's Tekton catalog, please visitstakater-tekton-catalog
. -
Provide values for
image_registry
, andhelm_registry
parameters. You can find the urls from hereimage_registry
url should be succeeded by your application name. Example: nexus-docker-stakater-nexus.apps.lab.kubeapp.cloud/review-api -
Create a pull request with you changes. This should trigger the pipeline in the build namespace.
Great! Let's add more tasks in our pipelineRun in coming tutorials.