3.4. Bitbucket Cloud での Pipelines as Code の使用
組織またはプロジェクトが優先プラットフォームとして Bitbucket Cloud を使用する場合、Bitbucket Cloud の Webhook を使用してリポジトリーに Pipelines as Code を使用できます。
前提条件
- Pipelines as Code がクラスターにインストールされている。
Bitbucket Cloud でアプリのパスワードを作成する。
以下のボックスをチェックして、適切なパーミッションをトークンに追加します。
-
アカウント:
メール
、読み取り
-
ワークスペースのメンバーシップ:
読み取り
、書き込み
-
プロジェクト:
読み取り
、書き込み
-
問題:
読み取り
、書き込み
プルリクエスト:
読み取り
、書き込み
注記-
tkn pac
CLI を使用して Webhook を設定する必要がある場合は、Webhooks
:Read
とWrite
パーミッションをトークンに追加します。 - 生成されたら、パスワードまたはトークンのコピーを別の場所に保存します。
-
-
アカウント:
手順
Webhook を設定し、
Repository
CR を作成します。tkn pac
CLI ツールを使用して webhook を設定し、リポジトリー
CR を 自動的に 作成するには、次のコマンドを使用します。$ 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 を設定して
Repository
CR を 手動 で作成するには、以下の手順を実行します。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>"
Repository
CR を作成します。例:
Repository
CRapiVersion: "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
パラメーターにコンマ区切りの値として追加します。
-
デフォルトの動作を無効にするには、
オプション: 既存の
Repository
CR の場合は、複数の Bitbucket Cloud Webhook シークレットを追加するか、削除されたシークレットの代わりに指定します。tkn pac
CLI ツールを使用して Webhook を追加します。例:
tkn pac
CLI を使用した 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
コマンドで使用するのは、Repository
CR がデフォルト以外の namespace に存在する場合のみです。-
既存の OpenShift
Secret
オブジェクトのwebhook.secret
キーを更新します。
オプション: 既存の
Repository
CR の場合は、Personal Access Token を更新します。tkn pac
CLI ツールを使用して Personal Access Token を更新します。例:
tkn pac
CLI を使用した 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
コマンドで使用するのは、Repository
CR がデフォルト以外の namespace に存在する場合のみです。または、
Repository
CR を変更して Personal Access Token を更新します。Repository
CR でシークレットの名前を見つけます。... spec: git_provider: user: "<BITBUCKET_USERNAME>" secret: name: "bitbucket-cloud-token" key: "provider.token" ...
oc patch
コマンドを使用して、$target_namespace
namespace の$password
の値を更新します。$ oc -n $target_namespace patch secret bitbucket-cloud-token -p "{\"data\": {\"provider.token\": \"$(echo -n $NEW_TOKEN|base64 -w0)\"}}"