3.4. Bitbucket Cloud での Pipelines as Code の使用
組織またはプロジェクトが優先プラットフォームとして Bitbucket Cloud を使用する場合、Bitbucket Cloud の Webhook を使用してリポジトリーに Pipelines as Code を使用できます。
前提条件
- Pipelines as Code がクラスターにインストールされている。
Bitbucket Cloud でアプリのパスワードを作成する。
以下のボックスをチェックして、適切なパーミッションをトークンに追加します。
-
アカウント:
Email、Read -
ワークスペースのメンバーシップ:
Read、Write -
プロジェクト:
Read、Write -
問題:
Read、Write プルリクエスト:
Read、Write注記-
tkn pacCLI を使用して Webhook を設定する必要がある場合は、Webhooks:ReadとWriteパーミッションをトークンに追加します。 - 生成されたら、パスワードまたはトークンのコピーを別の場所に保存します。
-
-
アカウント:
手順
Webhook を設定し、
RepositoryCR を作成します。tkn pacCLI ツールを使用して webhook を設定し、RepositoryCR を 自動的に 作成するには、次のコマンドを使用します。$ tkn pac create repo対話型出力の例
? Enter the Git repository url (default: https://bitbucket.org/workspace/repo): ? Please enter the namespace where the pipeline should run (default: repo-pipelines): ! Namespace repo-pipelines is not found ? Would you like me to create the namespace repo-pipelines? Yes ✓ Repository workspace-repo has been created in repo-pipelines namespace ✓ Setting up Bitbucket Webhook for Repository https://bitbucket.org/workspace/repo ? Please enter your bitbucket cloud username: <username> ℹ ️You now need to create a Bitbucket Cloud app password, please checkout the docs at https://is.gd/fqMHiJ for the required permissions ? Please enter the Bitbucket Cloud app password: ************************************ 👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com ? Do you want me to use it? Yes ✓ Webhook has been created on repository workspace/repo 🔑 Webhook Secret workspace-repo has been created in the repo-pipelines namespace. 🔑 Repository CR workspace-repo has been updated with webhook secret in the repo-pipelines namespace ℹ Directory .tekton has been created. ✓ A basic template has been created in /home/Go/src/bitbucket/repo/.tekton/pipelinerun.yaml, feel free to customize it.Webhook を設定して
RepositoryCR を 手動 で作成するには、以下の手順を実行します。OpenShift クラスターで、Pipelines as Code コントローラーの公開 URL を抽出します。
$ echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')Bitbucket Cloud で、以下の手順を実行します。
- Bitbucket Cloud リポジトリーの左側のナビゲーションペインを使用して Repository settings -> Webhooks に移動し、Add webhook をクリックします。
- Title を設定します。たとえば、"Pipelines as Code" です。
- URL を Pipelines as Code コントローラーのパブリック URL に設定します。
- Repository: Push、Pull Request: Created、Pull Request: Updated、および Pull Request: Comment created のイベントを選択します。
- Save をクリックします。
OpenShift クラスターで、ターゲット namespace に app パスワードを使用して
Secretオブジェクトを作成します。$ oc -n target-namespace create secret generic bitbucket-cloud-token \ --from-literal provider.token="<BITBUCKET_APP_PASSWORD>"RepositoryCR を作成します。例:
RepositoryCRapiVersion: "pipelinesascode.tekton.dev/v1alpha1" kind: Repository metadata: name: my-repo namespace: target-namespace spec: url: "https://bitbucket.com/workspace/repo" branch: "main" git_provider: user: "<BITBUCKET_USERNAME>"1 secret: name: "bitbucket-cloud-token"2 key: "provider.token" # Set this if you have a different key in your secret
注記-
tkn pac createおよびtkn pac bootstrapコマンドは Bitbucket Cloud ではサポートされていません。 Bitbucket Cloud では Webhook シークレットはサポートされません。ペイロードを保護し、CI のハイジャックを防止するために、Pipelines as Code は Bitbucket Cloud IP アドレスのリストをフェッチし、Webhook の受信がそれらの IP アドレスからのみ行われるようにします。
-
デフォルトの動作を無効にするには、
pipelinesAsCode.settings仕様のTektonConfigカスタムリソースでbitbucket-cloud-check-source-ipパラメーターをfalseに設定します。 -
追加の安全な IP アドレスまたはネットワークを許可するには、
pipelinesAsCode.settings仕様のTektonConfigカスタムリソースのbitbucket-cloud-additional-source-ipパラメーターにコンマ区切りの値として追加します。
-
デフォルトの動作を無効にするには、
オプション: 既存の
RepositoryCR の場合は、複数の Bitbucket Cloud Webhook シークレットを追加するか、削除されたシークレットの代わりに指定します。tkn pacCLI ツールを使用して Webhook を追加します。例:
tkn pacCLI を使用した Webhook の追加$ tkn pac webhook add -n repo-pipelines対話型出力の例
✓ Setting up Bitbucket Webhook for Repository https://bitbucket.org/workspace/repo ? Please enter your bitbucket cloud username: <username> 👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com ? Do you want me to use it? Yes ✓ Webhook has been created on repository workspace/repo 🔑 Secret workspace-repo has been updated with webhook secret in the repo-pipelines namespace.注記[-n <namespace>]オプションをtkn pac webhook addコマンドで使用するのは、RepositoryCR がデフォルト以外の namespace に存在する場合のみです。-
既存の OpenShift
Secretオブジェクトのwebhook.secretキーを更新します。
オプション: 既存の
RepositoryCR の場合は、Personal Access Token を更新します。tkn pacCLI ツールを使用して Personal Access Token を更新します。例:
tkn pacCLI を使用した Personal Access Token の更新$ tkn pac webhook update-token -n repo-pipelines対話型出力の例
? Please enter your personal access token: **************************************** 🔑 Secret owner-repo has been updated with new personal access token in the repo-pipelines namespace.注記[-n <namespace>]オプションをtkn pac webhook update-tokenコマンドで使用するのは、RepositoryCR がデフォルト以外の namespace に存在する場合のみです。または、
RepositoryCR を変更して Personal Access Token を更新します。RepositoryCR でシークレットの名前を見つけます。... spec: git_provider: user: "<BITBUCKET_USERNAME>" secret: name: "bitbucket-cloud-token" key: "provider.token" ...oc patchコマンドを使用して、$target_namespacenamespace の$passwordの値を更新します。$ oc -n $target_namespace patch secret bitbucket-cloud-token -p "{\"data\": {\"provider.token\": \"$(echo -n $NEW_TOKEN|base64 -w0)\"}}"
関連情報
- Creating app password on Bitbucket Cloud (Atlassian のドキュメント)
- Introducing Altassian Account ID and Nicknames (Atlassian ドキュメント)