Bitbucket webhook 在错误的 GIT 存储库上生成构建
Bitbucket webhook generating build on the wrong GIT repository
我想在 bitbucket 上发生事件(例如推送)时在我的 OpenShift 上触发一个管道。我按照 Openshift 文档页面上的说明正确配置了一个 webhook。虽然我不得不更改我的管道的 Openshift 模板,但它产生了一些冲突。
BuildConfig 如下所示:
- apiVersion: "v1"
kind: "BuildConfig"
metadata:
name: "${SERVICE_NAME}-pipeline"
spec:
source:
contextDir: '${APPLICATION_GIT_JENKINSFILE_REPO_CONTEXT_DIR}'
git:
ref: master
uri: '${APPLICATION_GIT_JENKINSFILE_REPO}'
sourceSecret:
name: git-secret
type: Git
strategy:
jenkinsPipelineStrategy:
jenkinsfilePath: Jenkinsfile
triggers:
type: "Bitbucket"
bitbucket:
secretReference:
name: "mysecret"
因此,在 'source' 组件上,我引用了我的 Jenkinsfile 所在的 git 存储库。这样我就可以有许多管道,只有一个集中的 Jenkinsfile。请注意,此存储库与我配置 webhook 的 api 的位置完全不同。
由于发送到 Openshift 的负载具有相应 api 存储库更改的提交 ID,因此这种方法在自动触发时失败。 Openshift(我不知道为什么)尝试将该提交与此模板上存在的回购(Jenkinsfile 回购)相关联。
日志如下:
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://jenkinsfile-repo.git # timeout=10
Fetching upstream changes from http://jenkinsfile-repo.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials git-secret
> git fetch --tags --progress http://jenkinsfile-repo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit} # timeout=10
hudson.plugins.git.GitException: Command "git rev-parse 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}" returned status code 128:
stdout: 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}
stderr: fatal: ambiguous argument '79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2016)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1984)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1980)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1612)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1624)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:809)
at hudson.plugins.git.GitAPI.revParse(GitAPI.java:316)
at hudson.plugins.git.RevisionParameterAction.toRevision(RevisionParameterAction.java:98)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1070)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1187)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:144)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
我们可以看到我试图解释的行为,'79370e4fa88f19c693d85d82fbdbed77620d048b' 是 api 存储库上的提交 ID,OpenShift 试图将其与 jenkinsfile 存储库相关联。
例如,如果我可以忽略有效载荷,问题就不会存在。
感谢您的帮助。
我认为您不需要输入类型:git(重复)并尝试使用 https:// bitbucket url,
source:
contextDir: '${APPLICATION_GIT_JENKINSFILE_REPO_CONTEXT_DIR}'
git:
ref: master
uri: '${APPLICATION_GIT_JENKINSFILE_REPO}'
sourceSecret:
name: git-secret
type: Git *****remove and try ?
我设法实施了一个解决方法,但我仍然不明白为什么会出现我之前指定的行为。
基本上当前的解决方案是这样的:
openshift 模板引用了各自 API 的 GIT 存储库,并且该存储库有自己的 Jenkinsfile,每个 API 都相同。虽然,这个 Jenkinsfile 唯一做的就是调用一个 groovy 脚本,该脚本集中在一个单独的 GIT 存储库中,并在 Jenkins 中声明为共享库。
这样,如果我们必须改变某些东西,例如管道的一个阶段,我们只需要改变一个位置,也就是开始的 objective。
我想在 bitbucket 上发生事件(例如推送)时在我的 OpenShift 上触发一个管道。我按照 Openshift 文档页面上的说明正确配置了一个 webhook。虽然我不得不更改我的管道的 Openshift 模板,但它产生了一些冲突。
BuildConfig 如下所示:
- apiVersion: "v1"
kind: "BuildConfig"
metadata:
name: "${SERVICE_NAME}-pipeline"
spec:
source:
contextDir: '${APPLICATION_GIT_JENKINSFILE_REPO_CONTEXT_DIR}'
git:
ref: master
uri: '${APPLICATION_GIT_JENKINSFILE_REPO}'
sourceSecret:
name: git-secret
type: Git
strategy:
jenkinsPipelineStrategy:
jenkinsfilePath: Jenkinsfile
triggers:
type: "Bitbucket"
bitbucket:
secretReference:
name: "mysecret"
因此,在 'source' 组件上,我引用了我的 Jenkinsfile 所在的 git 存储库。这样我就可以有许多管道,只有一个集中的 Jenkinsfile。请注意,此存储库与我配置 webhook 的 api 的位置完全不同。
由于发送到 Openshift 的负载具有相应 api 存储库更改的提交 ID,因此这种方法在自动触发时失败。 Openshift(我不知道为什么)尝试将该提交与此模板上存在的回购(Jenkinsfile 回购)相关联。
日志如下:
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://jenkinsfile-repo.git # timeout=10
Fetching upstream changes from http://jenkinsfile-repo.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials git-secret
> git fetch --tags --progress http://jenkinsfile-repo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit} # timeout=10
hudson.plugins.git.GitException: Command "git rev-parse 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}" returned status code 128:
stdout: 79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}
stderr: fatal: ambiguous argument '79370e4fa88f19c693d85d82fbdbed77620d048b^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2016)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1984)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1980)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1612)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1624)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:809)
at hudson.plugins.git.GitAPI.revParse(GitAPI.java:316)
at hudson.plugins.git.RevisionParameterAction.toRevision(RevisionParameterAction.java:98)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1070)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1187)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:144)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
我们可以看到我试图解释的行为,'79370e4fa88f19c693d85d82fbdbed77620d048b' 是 api 存储库上的提交 ID,OpenShift 试图将其与 jenkinsfile 存储库相关联。
例如,如果我可以忽略有效载荷,问题就不会存在。
感谢您的帮助。
我认为您不需要输入类型:git(重复)并尝试使用 https:// bitbucket url,
source: contextDir: '${APPLICATION_GIT_JENKINSFILE_REPO_CONTEXT_DIR}' git: ref: master uri: '${APPLICATION_GIT_JENKINSFILE_REPO}' sourceSecret: name: git-secret type: Git *****remove and try ?
我设法实施了一个解决方法,但我仍然不明白为什么会出现我之前指定的行为。
基本上当前的解决方案是这样的:
openshift 模板引用了各自 API 的 GIT 存储库,并且该存储库有自己的 Jenkinsfile,每个 API 都相同。虽然,这个 Jenkinsfile 唯一做的就是调用一个 groovy 脚本,该脚本集中在一个单独的 GIT 存储库中,并在 Jenkins 中声明为共享库。
这样,如果我们必须改变某些东西,例如管道的一个阶段,我们只需要改变一个位置,也就是开始的 objective。