How do I access the current Heroku release version programmatically?

后端 未结 5 1613
一整个雨季
一整个雨季 2021-02-18 19:22

Is this even possible - is there something like a RELEASE_VERSION environment variable?

5条回答
  •  悲&欢浪女
    2021-02-18 19:38

    I know it's an oldie, but I didn't find a definite answer anywhere else, so I'm posting it here in case anyone stumbles upon this question. I added an initializer, called deploy_version.rb with the followin content:

        if ENV['HEROKU_APP']
            res = `curl -H "Accept: application/json" -u :#{ENV['HEROKU_API_KEY']} -X GET https://api.heroku.com/apps/#{ENV['HEROKU_APP']}/releases`
            last = JSON.parse(res).last
            $deploy_version = last['name']
        else
            $deploy_version = 'local'
        end
    

    Then it's easy to display it in your app:

       
    

提交回复
热议问题