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:ReadWrite パーミッションをトークンに追加します。
        • 生成されたら、パスワードまたはトークンのコピーを別の場所に保存します。

手順

  1. 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 を 手動 で作成するには、以下の手順を実行します。

      1. OpenShift クラスターで、Pipelines as Code コントローラーの公開 URL を抽出します。

        $ echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')
      2. Bitbucket Cloud で、以下の手順を実行します。

        1. Bitbucket Cloud リポジトリーの左側のナビゲーションペインを使用して Repository settings -> Webhooks に移動し、Add webhook をクリックします。
        2. Title を設定します。たとえば、"Pipelines as Code" です。
        3. URL を Pipelines as Code コントローラーのパブリック URL に設定します。
        4. Repository: PushPull Request: CreatedPull Request: Updated、および Pull Request: Comment created のイベントを選択します。
        5. Save をクリックします。
      3. OpenShift クラスターで、ターゲット namespace に app パスワードを使用して Secret オブジェクトを作成します。

        $ oc -n target-namespace create secret generic bitbucket-cloud-token \
          --from-literal provider.token="<BITBUCKET_APP_PASSWORD>"
      4. Repository CR を作成します。

        例: Repository CR

        apiVersion: "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

        1
        所有者ファイルの ACCOUNT_ID からしかユーザーの参照はできません。
        2
        Pipelines as Code は、git_provider.secret 仕様で参照され、Repository CR が同じ namespace にあることを前提としています。
    注記
    • 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 パラメーターにコンマ区切りの値として追加します。
  2. オプション: 既存の Repository CR の場合は、複数の Bitbucket Cloud Webhook シークレットを追加するか、削除されたシークレットの代わりに指定します。

    1. 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 に存在する場合のみです。

    2. 既存の OpenShift Secret オブジェクトの webhook.secret キーを更新します。
  3. オプション: 既存の 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 を更新します。

      1. Repository CR でシークレットの名前を見つけます。

        ...
        spec:
          git_provider:
            user: "<BITBUCKET_USERNAME>"
            secret:
              name: "bitbucket-cloud-token"
              key: "provider.token"
        ...
      2. 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)\"}}"
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.