问题描述
此stackoverflow页面可以帮助您使用通用Webhook触发器在Jenkins中检出Bitbucket拉取请求.
This stackoverflow page can help you checkout bitbucket pull requests in Jenkins with Generic webhook trigger.
先决条件:
詹金斯:1)在Jenkins中安装通用Webhook触发插件和Bitbucket插件
Jenkins:1) Installing Generic Webhook Trigger Plugin and Bitbucket plugin in Jenkins
2)在Jenkins配置中配置"Bitbucket端点".
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)
Bitbucket:4)在bitbucket存储库中配置Webhook以连接到Jenkins webhook插件并检查事件"-推送,添加注释.
Bitbucket:4) Configuring Webhook in bitbucket repo to connect to Jenkins webhook plugin and checking 'Events' - Push, Comment Added.
现在假设您可以通过评论从bitbucket公关触发Jenkins工作.
Now assuming you can trigger Jenkins job from your bitbucket PR's by commenting.
我在触发后克隆位桶请求请求时遇到问题.它与Git SCM配置有关.
下面是我解决此问题的方法.
Below is the way I resolved this issue.
1)在示例管道作业中,选中通用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)在后内容参数"下创建一个表达式值为"
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参数进行位桶提取请求检出的GIT SCM配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!