tektontekton-pipelines

How to get the brach name from a bitbucket PR trigger in Tekton?


I'm building a Tekton pipeline where I need to get all the modified files in a PR. This pipeline is initiated by a Bitbucket Pull Request web hook. The problem is the web hook payload includes the commit hash, but not the branch. So I have a task to clone the repo, but I can't pass the branch name to that task since that information isn't provided from the payload. According to Tekton, these are the variables I have available to me from the bitbucket-pullreq trigger:

gitrepo-url
pullreq-sha
pullreq-state
pullreq-number
pullreq-repo-name
pullreq-html-url
pullreq-title
user-type

I can get the branch name from the PR # by using the Bitbucket API. Is there a way to set that branch name as a variable so that I can clone the correct branch in another task? Similar to Ansible's set_fact module.

My other option is to build a custom task to query the Bitbucket API for the branch name, then checkout that branch and do what I need to do, but I'd rather not do that if I can avoid it.


Solution

  • I realized instead of finding the branch name I can check out the commit hash instead of the branch:

    params:
      - name: url
        value: $(params.gitrepo-url)
      - name: revision
        value: $(params.pullreq-sha)