Jenkins 使用通用Webhook参数签出bitbucket pull请求的GIT SCM配置

Jenkins 使用通用Webhook参数签出bitbucket pull请求的GIT SCM配置,jenkins,jenkins-pipeline,bitbucket,jenkins-plugins,bitbucket-pipelines,Jenkins,Jenkins Pipeline,Bitbucket,Jenkins Plugins,Bitbucket Pipelines,此stackoverflow页面可以帮助您使用通用webhook触发器签出Jenkins中的bitbucket pull请求 先决条件: 詹金斯: 1) 在Jenkins中安装通用Webhook触发器插件和Bitbucket插件 2) 在Jenkins配置中配置“Bitbucket端点” 3) 在Jenkins中创建示例“管道”作业(可以配置通用webhook插件/配置bitbucket repo/包括自定义Jenkins文件路径) 比特桶: 4) 在bitbucket repo中配置Webho

此stackoverflow页面可以帮助您使用通用webhook触发器签出Jenkins中的bitbucket pull请求

先决条件:

詹金斯: 1) 在Jenkins中安装通用Webhook触发器插件和Bitbucket插件

2) 在Jenkins配置中配置“Bitbucket端点”

3) 在Jenkins中创建示例“管道”作业(可以配置通用webhook插件/配置bitbucket repo/包括自定义Jenkins文件路径)

比特桶: 4) 在bitbucket repo中配置Webhook以连接到Jenkins Webhook插件,并检查“事件”-推送,评论补充

现在假设你可以通过评论从你的比特桶公关中触发詹金斯的工作

触发后克隆bitbucket拉取请求时遇到问题。这与Git SCM配置有关。

下面是我解决这个问题的方法

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

2) 使用表达式值在“发布内容参数”下创建变量“分支”

$.pullRequest.fromRef.displayId 
(可以从控制台输出中的post内容派生)并选中“JSON路径”

以下是管道Git SCM配置:

Name: origin
RefSpec: +refs/heads/${BRANCH}
Branches to build
  Branch Specifier (blank for 'any'): **/pull-requests/**
在以上述方式配置后,我成功地解决了此克隆PR的问题

我尝试使用bitbucket pr id,但在尝试签出pr时,仅在“管道脚本”中工作,如下所示:

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具有表达式值

$.pullRequest.id

您还可以使用以下方法尝试GIT SCM配置:

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

其中,分支值为“$.pullRequest.fromRef.displayId”,从通用Webhook触发器post参数中检索。

您还可以使用以下命令尝试GIT SCM配置:```Name:FETCH_HEAD`RefSpec:`refs/heads/*:refs/remotes/origin/*分支说明符:*/${BRANCH}其他行为:1。清除存储库并强制克隆2。签出后清除“`”,其中分支值为“$.pullRequest.fromRef.displayId”,从通用Webhook触发器post参数中检索。