3.5. Using Pipelines as Code with Bitbucket Data Center
If your organization or project uses Bitbucket Data Center as the preferred platform, you can use Pipelines as Code for your repository with a webhook on Bitbucket Data Center.
Prerequisites
- Ensure that Pipelines as Code is installed on the cluster.
Generate a personal access token as the manager of the project on Bitbucket Data Center, and save a copy of it in an alternate location.
注記-
The token must have the
PROJECT_ADMINandREPOSITORY_ADMINpermissions. - The token must have access to forked repositories in pull requests.
-
The token must have the
Procedure
On your OpenShift cluster, extract the public URL of the Pipelines as Code controller.
$ echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')On Bitbucket Data Center, perform the following steps:
- Use the left navigation pane of your Bitbucket Data Center repository to go to Repository settings –> Webhooks and click Add webhook.
- Set a Title. For example, "Pipelines as Code".
- Set the URL to the Pipelines as Code controller public URL.
Add a webhook secret and save a copy of it in an alternate location. If you have
opensslinstalled on your local machine, generate a random secret using the following command:$ openssl rand -hex 20Select the following events:
- Repository: Push
- Repository: Modified
- Pull Request: Opened
- Pull Request: Source branch updated
- Pull Request: Comment added
- Click Save.
On your OpenShift cluster, create a
Secretobject with the app password in the target namespace.$ oc -n target-namespace create secret generic bitbucket-datacenter-webhook-config \ --from-literal provider.token="<PERSONAL_TOKEN>" \ --from-literal webhook.secret="<WEBHOOK_SECRET>"Create a
RepositoryCR.Example:
RepositoryCRapiVersion: "pipelinesascode.tekton.dev/v1alpha1" kind: Repository metadata: name: my-repo namespace: target-namespace spec: url: "https://bitbucket.com/workspace/repo" git_provider: url: "https://bitbucket.datacenter.api.url/rest"1 user: "<BITBUCKET_USERNAME>"2 secret:3 name: "bitbucket-datacenter-webhook-config" key: "provider.token" # Set this if you have a different key in your secret webhook_secret: name: "bitbucket-datacenter-webhook-config" key: "webhook.secret" # Set this if you have a different key for your secret- 1
- Ensure that you have the right Bitbucket Data Center API URL without the
/api/v1.0suffix. Usually, the default install has a/restsuffix. - 2
- You can only reference a user by the
ACCOUNT_IDin an owner file. - 3
- Pipelines as Code assumes that the secret referred in the
git_provider.secretspec and theRepositoryCR is in the same namespace.
注記The
tkn pac createandtkn pac bootstrapcommands are not supported on Bitbucket Data Center.
Additional resources
- Creating personal tokens on Bitbucket Data Center (Atlassian documentation)
- Managing webhooks on Bitbucket Data Center (Atlassian documentation)