使用通用 Webhook 参数检出 bitbucket 拉取请求的 GIT SCM 配置 [英] GIT SCM configuration for bitbucket pull requests checkout using generic Webhook parameters

查看:35
本文介绍了使用通用 Webhook 参数检出 bitbucket 拉取请求的 GIT SCM 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此 stackoverflow 页面可以帮助您使用通用 webhook 触发器在 Jenkins 中检查 bitbucket 拉取请求.

This stackoverflow page can help you checkout bitbucket pull requests in Jenkins with Generic webhook trigger.

先决条件:

詹金斯:1) 在 Jenkins 中安装 Generic Webhook Trigger Plugin 和 Bitbucket 插件

Jenkins: 1) Installing Generic Webhook Trigger Plugin and Bitbucket plugin in Jenkins

2) 在 Jenkins 配置中配置Bitbucket Endpoints".

2) Configuring 'Bitbucket Endpoints' in Jenkins configuration.

3) 在 Jenkins 中创建示例管道"作业(可以配置通用 webhook 插件/配置 bitbucket 存储库/包含自定义 Jenkins 文件路径)

3) Creating sample 'Pipeline' job in Jenkins (can configure Generic webhook plugin / configure bitbucket repo / include custom Jenkins file path)

比特桶:4) 在 bitbucket repo 中配置 Webhook 以连接到 Jenkins webhook 插件并检查事件" - 推送,添加评论.

Bitbucket: 4) Configuring Webhook in bitbucket repo to connect to Jenkins webhook plugin and checking 'Events' - Push, Comment Added.

现在假设您可以通过评论从您的 bitbucket PR 中触发 Jenkins 作业.

Now assuming you can trigger Jenkins job from your bitbucket PR's by commenting.

我在触发后克隆 bitbucket 拉取请求时遇到问题.它与 Git SCM 配置有关.

以下是我解决此问题的方法.

Below is the way I resolved this issue.

1) 在您的示例管道作业中,选中 Generic Webhook 插件下的打印帖子内容".您可以在作业控制台输出中看到 json 内容.

1) In your sample pipeline job, check 'Print post content' under Generic Webhook plugin. You can see json content in the job console output.

2) 在发布内容参数"下创建一个变量BRANCH",表达式值为:

2) Create a variable 'BRANCH' under 'Post content parameters' with expression value:

$.pullRequest.fromRef.displayId 

(可以从控制台输出中的帖子内容导出)并检查JSON路径".

(can be derived from post content in console output) and check 'JSON path'.

下面是管道 Git SCM 配置:

Below is the pipeline Git SCM configuration:

Name: origin
RefSpec: +refs/heads/${BRANCH}
Branches to build
  Branch Specifier (blank for 'any'): **/pull-requests/**

通过上述方式配置后,我成功解决了这个克隆 PR 的问题.

I was successful in resolving this cloning PR's issue after configuring in the above way.

我尝试使用 bitbucket pr id,但当我尝试如下检查 PR 时仅在管道脚本"中工作:

I tried using the bitbucket pr id but worked only in 'Pipeline Script' when I tried to checkout the PR as below:

checkout([$class: 'GitSCM',
                        branches: [[name: 'FETCH_HEAD']],
                        extensions: [[$class: 'LocalBranch']],
                        userRemoteConfigs: [[refspec: "+refs/pull-requests/${PR_ID}/from:pr/${PR_ID}", credentialsId: '*****', url: 'https://stash***************.git']]
                        ])

其中 PR_ID 具有表达式值

where PR_ID has expression value

$.pullRequest.id

推荐答案

你也可以尝试使用 GIT SCM 配置:

Also you can try GIT SCM configuration using:

Name: FETCH_HEAD`
RefSpec: +refs/heads/*:refs/remotes/origin/*
Branch Specifier: **/${BRANCH}
Additional Behaviours:
1. Wipe out repository & force clone
2. Clean after checkout 

其中 BRANCH 值是从通用 Webhook 触发器发布参数中检索到的$.pullRequest.fromRef.displayId".

where BRANCH value is '$.pullRequest.fromRef.displayId' retrieved from Generic Webhook trigger post parameters.

这篇关于使用通用 Webhook 参数检出 bitbucket 拉取请求的 GIT SCM 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆