嗯,Jenkins直接联动Bitbucket,创建的Job通过指定授权方式拉取所需分支,并当有推送时自动触发Job。

核心插件是:Bitbucket Server Integration

下面简要记录联动流程:

  1. Jenkins

    通过Manage Jenkins->Plugins->Available plugins,安装好Bitbucket Server Integration插件

  2. Bitbucket

    管理员点击右上角自己的头像,弹出菜单后点击 Manage account

  3. Bitbucket

    左侧菜单点击 HTTP access tokens,然后点击 Create token 按钮,以默认设置创建个永不过期的token并记录下来。

  4. Jenkins

    通过Manage Jenkins,进入 System 页面

  5. Jenkins

    下拉找到并点击 Bitbucket Server integration 下方的 Add a Bitbucket Server instance,在展开菜单点击 Instance details.

    Bitbucket Server integration

  6. Jenkins

    Instance details ,中按情况填写基本信息,点击 Personal access token 下方的 Add-> Jenkins,弹出 Jenkins Credentials Provider: Jenkins 页。

  7. Jenkins

    Kind 下拉选择 Bitbucket personal access token,在 Token 输入框填入刚创建好的永不过期的token,其他按需填写后点击 Add

  8. Jenkins

    再次点击下拉选择 Personal access token,选择刚创建好的认证信息,点击右侧 Test connection,如果提示:“Jenkins can connect with Bitbucket Server.”,则说明一切正常,点击 Save 保存好基本配置。

  9. Jenkins

    通过Manage Jenkins,进入 Manage Bitbucket Server consumers 页面

  10. Jenkins

    点击 Register new consumer,进入 Create New Consumer 页面

  11. Jenkins

    以下示例自己按实际情况修改:

    Consumer name -> Bitbucket
    Consumer key -> Bitbucket-key 
    Shared secret -> Bitbucket-secret
    Callback URL -> https://127.0.0.1:7990

    其中Callback URL是我Bitbucket的地址,之后保存会进入基本信息页,别关闭,后面Bitbucket要用。

    Create New Consumer

  12. Bitbucket

    管理员进入后台-> Application Links

  13. Bitbucket

    点击右上 Create link

  14. Bitbucket

    Application type 保持默认的 Atlassian product 选项。

    Application URL 填Jenkins的地址,例如:https://127.0.0.1:8080,之后点击 Continue 按钮,进入下一个步骤。

    Create link

  15. Bitbucket

    按刚才设置的密钥等信息填写,其中URL的部分就是刚让你不要关闭的消费者的基本信息页里对应项,填写完毕后点 Continue

    Link applications

到这里,Jenkins联动Bitbucket就做完了。你创建的Job中,Source Code Management 的选项下,选择 Bitbucket Server,就可以启用相关代码逻辑,当然,首次还需要在Credentials (for build auth)创建个Bitbucket的凭证,至于其他自动化,Build Steps 选 Execute shell,己举一反三吧。


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《Jenkins联动Bitbucket简要记录》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌