搜索

3.5. 在 Bitbucket Server 中使用 Pipelines as Code

download PDF

如果您的机构或项目使用 Bitbucket Cloud 作为首选平台,您可以在 Bitbucket Server 上使用带有 webhook 的仓库的 Pipelines as Code。

先决条件

  • 确保在集群中安装了 Pipelines as Code。
  • 在 Bitbucket 服务器上,生成个人访问令牌作为项目管理器,并将它保存到一个其他位置中。

    注意
    • 令牌必须具有 PROJECT_ADMINREPOSITORY_ADMIN 权限。
    • 令牌必须有权访问拉取请求中分叉的存储库。

流程

  1. 在 OpenShift 集群中,提取 Pipelines as Code 控制器的公共 URL。

    $ echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')
  2. 在 Bitbucket 服务器上,执行以下步骤:

    1. 使用 Bitbucket Data Center 存储库的左侧导航窗格,进入 Repository settings -> Webhooks 并点 Add webhook
    2. 设置 Title。例如,"Pipelines as Code"。
    3. URL 设置为 Pipelines as Code 控制器公共 URL。
    4. 添加 webhook secret,并将它的副本保存到备用位置。如果您在本地机器上安装了 openssl,使用以下命令生成随机 secret:

      $ openssl rand -hex 20
    5. 选择以下事件:

      • Repository: Push
      • Repository: Modified
      • Pull Request: Opened
      • Pull Request: Source branch updated
      • Pull Request: Comment added
    6. 点击 Save
  3. 在 OpenShift 集群中,使用目标命名空间中的 app 密码创建一个 Secret 对象。

    $ oc -n target-namespace create secret generic bitbucket-server-webhook-config \
      --from-literal provider.token="<PERSONAL_TOKEN>" \
      --from-literal webhook.secret="<WEBHOOK_SECRET>"
  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"
      git_provider:
        url: "https://bitbucket.server.api.url/rest" 1
        user: "<BITBUCKET_USERNAME>" 2
        secret: 3
          name: "bitbucket-server-webhook-config"
          key: "provider.token" # Set this if you have a different key in your secret
        webhook_secret:
          name: "bitbucket-server-webhook-config"
          key: "webhook.secret" # Set this if you have a different key for your secret

    1
    确保具有不带 /api/v1.0 后缀的正确的 Bitbucket 服务器 API URL。通常,默认安装有一个 /rest 后缀。
    2
    您只能通过所有者文件中的 ACCOUNT_ID 引用用户。
    3
    Pipelines as Code 假设 git_provider.secret spec 引用的 secret 和Repository CR 位于同一命名空间中。
    注意

    Bitbucket 服务器不支持 tkn pac createtkn pac bootstrap 命令。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.