使用通用Webhook参数进行位桶提取请求检出的GIT SCM配置

时间:2019-06-18 22:01:44

标签: jenkins jenkins-pipeline bitbucket jenkins-plugins bitbucket-pipelines

此stackoverflow页面可以帮助您使用通用webhook触发器在Jenkins中签出位桶提取请求。

先决条件:

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

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

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

Bitbucket: 4)在bitbucket存储库中配置Webhook以连接到Jenkins webhook插件并检查“事件”-推送,添加注释。

现在假设您可以通过评论从bitbucket公关触发Jenkins工作。

我在触发后克隆位桶提取请求时遇到问题。它与Git SCM配置有关。

下面是我解决此问题的方法。

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

2)在“后内容参数”下创建一个表达式值为“

的变量“ 分支
for line in data:
    print(line.decode().strip())

(可以从控制台输出中的帖子内容派生)并检查“ JSON路径”。

以下是管道Git SCM配置:

$.pullRequest.fromRef.displayId 

以上述方式配置后,我成功解决了此克隆PR的问题。

我尝试使用bitbucket pr id,但在尝试检出PR时,只能在“管道脚本”中使用,如下所示:

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

其中PR_ID具有表达式值

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']]
                        ])

1 个答案:

答案 0 :(得分:-1)

您还可以使用以下方法尝试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 

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

相关问题