git - 从 Gitlab webhook 触发 Jenkins 管道

标签 git jenkins

刚开始使用 Jenkins,我似乎无法了解如何正确配置管道的 SCM,因为那里没有 SCM 配置选项卡。我已经向我的 gitlab 项目添加了一个带有 URL 的 webhook

http://my-jenkins-server.com/git/notifyCommit?url=https://my-gitlab-server.com/my-repo.git

但是当我访问该 URL 时,Jenkins 告诉我

No Git consumers using SCM API plugin for: https://my-gitlab-server.com/my-repo.git

这是有道理的,因为我没有明确告诉 Jenkins 我的管道与此存储库相关联,只是隐式地在 Jenkins 脚本中:

stage('Build'){
    git url: 'https://my-gitlab-server.com/my-repo.git', branch: 'master', credentialsId: '<some-hash>'
    sh 'cd linux-native; make clean all'
}

那么我如何告诉 Jenkins PIPELINE 与特定的存储库相关联?或者,如何找到适合我的管道的 notifyCommit url?

最佳答案

假设您已启用 Poll SCM选项,Git webhooks 的功能应该与 Freestyle 作业的功能相同。

但是在 /git/notifyCommit Hook 起作用之前,您需要至少手动运行管道一次。

对于 Freestyle 项目,Jenkins 可以相当轻松地检查作业配置并查看配置了哪个 SCM。对于脚本化管道,Jenkins 在实际执行管道之前无法确定您正在使用的 SCM(如果有)。

关于git - 从 Gitlab webhook 触发 Jenkins 管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42132189/

相关文章:

java - Git:将文件自动 merge 为冲突文件

git - 如何将所有提交从特定用户移动到新分支?

javascript - 可以通过浏览器访问远程 json 组件,但不能通过 $.getJSON() 以编程方式访问

github - 在 GitHub 合并事件上触发 Jenkins 构建

git - 在 Github 中 merge pull 请求时触发 Jenkins 构建

Linux 混帐 : Unable to access remote: error setting certificate verify locations

git - 根据克隆 super 仓库的位置,如何引用 git 子模块的备用 URL?

git - 可移植 Git 和 GitHub : SSH Keys

java - Jenkins Slave 静态分析失败

java - pom.xml 文件中的 mvn -x 开关