从Heroku应用程序中访问当前的git提交号码 [英] Access current git commit number from within Heroku app

查看:100
本文介绍了从Heroku应用程序中访问当前的git提交号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 slug编译器 .git 目录创建一个heroku slug,但有什么办法来配置Heroku,以便我可以从我的脚本中访问当前正在运行的git commit号码吗?



我希望能够在我的sinatra应用程序(在Heroku中运行)上有一个小链接,它说:运行版本e72fb274a0 (或类似的东西)。我怎么检索这个,或强制slug编译器将它添加到环境变量?



进度:



我认为最好的方法是创建一个自定义的buildpack,在删除.git目录之前将git commit版本号写入heroku slug。



我试过这样做(请参阅我的红宝石buildpack的分支 a>)但我添加的行 - line 23 a> - 似乎没有做这项工作。 Heroku认为&使用新的buildpack,但似乎并没有将文件写入slug。



任何人都知道为什么我的定制buildpack不能按预期工作吗?

p>

谢谢,

JP

解决方案

您可以在部署之前运行一个脚本来存储这些信息(也许是在YAML上)使用这些a =`ls`来注释

(注意不是''撇号'符号是'反向accute'符号)

变量将得到这个bash命令的结果,
所以你可以做
git =`git log `
然后找到你想要的信息并存储它。
所以你以后可以找回它。



这有帮助吗?


I know the slug compiler removes the .git directory when creating a heroku slug, but is there any way to configure Heroku so that I can access the currently running git commit number from within my scripts?

I'd like to be able to have a small link on my sinatra app (run within Heroku) which says "running version e72fb274a0" (or something similar). How can I retrieve this, or force the slug compiler to add it to an environment variable?

PROGRESS:

I reckon the best way to do this is to make a custom buildpack which writes the git commit version number to the heroku slug before the .git directory is deleted.

I've tried to do this (see my fork of the ruby buildpack) but the line I've added – line 23 – doesn't seem to be doing the job. Heroku sees & uses the new buildpack, but doesn't seem to write the file to the slug.

Anyone have any idea why my custom buildpack isn't working as expected?

Thanks,

JP

解决方案

You can run a script before deploy that store this information (maybe on a YAML)

using these a = `ls` (note that is not ' "apostrophe" sign is ` "inverse accute" sign)
the a variable will have the result of this bash command,
so you can do git = `git log` and then find the information you want it and store it. So you will be able to retrieve it later.

Did this helped ?

这篇关于从Heroku应用程序中访问当前的git提交号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆