git 子模块中的提交如何触发持续集成中的构建?
How can a commit in git submodule trigger a build in continuous integration?
我正在处理项目 A,A 依赖于 fast-developing 项目 B(它的主分支)。
因此,B是A的子模块,每次构建A,B也是re-built。此外,每次 B 有一个新的提交,我需要构建 B,然后 re-built A。(幸运的是,项目足够小,所以编译时间并不重要)。
现在,重点来了。当项目 A 或 B 中有新提交时,我想在 Travis CI 或其他持续集成服务中触发新构建。
我刚试过 Github 和特拉维斯 CI。项目 B 中的提交不会触发项目 A 中的构建。有没有简单的方法来 运行 这样的持续集成?
A commit in project B would not trigger a build in project A
这是预料之中的,考虑到 B 不知道 A 存在。
您需要记录项目 A 的 B 的新状态(新 gitlink, special entry in the index):
cd /path/to/projectA
git submodule update --remote
git add .
git commit -m "Record new B SHA1 gitlink"
git push
git submodule update --remote
会将子模块 B 更新为 B 的 A .gitmodules
文件中记录的分支的最新提交。
参见“git submodule tracking latest" and "Git submodules: Specify a branch/tag”
然后将为 A 触发一个新的 Travis 构建。
如果你想自动化上述序列,你需要一个 webhook (GitHub) (or BitBucket) projectB 和一个本地侦听器,在 repo B 上的推送事件中,将触发之前在 a 中提到的命令项目 A 的本地回购。
根据@VonC 的问题,我解决了这个问题。
参考 https://developer.github.com/webhooks/configuring/
- 我设置了项目Monitor,它有两个子模块,项目A和B
- 在项目 Monitor
中创建文件 trigger.rb
需要'sinatra'
post '/payload' do
system("git submodule update --remote")
system("git add .")
system("git commit -m Record_new_change")
system("git push")
puts "Finished handling"
end
- Download ngrok,运行 它在 VPS 或长 运行ning 计算机上
./ngrok http 4567
。你可能会得到一个 link 比如 http://7e9ea9dc.ngrok.io
- 运行
ruby trigger.rb
- 将项目 B 分叉到 B',编写另一个脚本以确保所有提交都同步到项目 B'
- 转到项目设置页面,创建一个新的 webhook,其 url 是
http://7e9ea9dc.ngrok.io/payload
用于项目 A 和 B'
- 将项目监视器添加到 Travis CI
这样A和B的开发就不会被触及,新的构建可以自动触发。
我已经使用 gitlab-ci 在更新子模块时触发父管道。请检查
我正在处理项目 A,A 依赖于 fast-developing 项目 B(它的主分支)。
因此,B是A的子模块,每次构建A,B也是re-built。此外,每次 B 有一个新的提交,我需要构建 B,然后 re-built A。(幸运的是,项目足够小,所以编译时间并不重要)。
现在,重点来了。当项目 A 或 B 中有新提交时,我想在 Travis CI 或其他持续集成服务中触发新构建。
我刚试过 Github 和特拉维斯 CI。项目 B 中的提交不会触发项目 A 中的构建。有没有简单的方法来 运行 这样的持续集成?
A commit in project B would not trigger a build in project A
这是预料之中的,考虑到 B 不知道 A 存在。
您需要记录项目 A 的 B 的新状态(新 gitlink, special entry in the index):
cd /path/to/projectA
git submodule update --remote
git add .
git commit -m "Record new B SHA1 gitlink"
git push
git submodule update --remote
会将子模块 B 更新为 B 的 A .gitmodules
文件中记录的分支的最新提交。
参见“git submodule tracking latest" and "Git submodules: Specify a branch/tag”
然后将为 A 触发一个新的 Travis 构建。
如果你想自动化上述序列,你需要一个 webhook (GitHub) (or BitBucket) projectB 和一个本地侦听器,在 repo B 上的推送事件中,将触发之前在 a 中提到的命令项目 A 的本地回购。
根据@VonC 的问题,我解决了这个问题。 参考 https://developer.github.com/webhooks/configuring/
- 我设置了项目Monitor,它有两个子模块,项目A和B
- 在项目 Monitor 中创建文件
trigger.rb
需要'sinatra'
post '/payload' do
system("git submodule update --remote")
system("git add .")
system("git commit -m Record_new_change")
system("git push")
puts "Finished handling"
end
- Download ngrok,运行 它在 VPS 或长 运行ning 计算机上
./ngrok http 4567
。你可能会得到一个 link 比如http://7e9ea9dc.ngrok.io
- 运行
ruby trigger.rb
- 将项目 B 分叉到 B',编写另一个脚本以确保所有提交都同步到项目 B'
- 转到项目设置页面,创建一个新的 webhook,其 url 是
http://7e9ea9dc.ngrok.io/payload
用于项目 A 和 B' - 将项目监视器添加到 Travis CI
这样A和B的开发就不会被触及,新的构建可以自动触发。
我已经使用 gitlab-ci 在更新子模块时触发父管道。请检查