# Supply build version via env variable

**URL:** <https://community.fly.io/t/supply-build-version-via-env-variable/1667>\
**Category:** Questions / Help\
**Tags:** wishlist\
**Created:** [June 7, 2021, 11:07pm UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667 "2021-06-07T23:07:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![james](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/james/32/412_2.png) [@james](https://community.fly.io/u/james)\
**Post date:** [June 7, 2021, 11:07pm UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/1 "2021-06-07T23:07:47Z")

</div>

When deploying new versions of my app I can get the [Fly.io](http://Fly.io) instance ID via the ` FLY_ALLOC_ID` but there is no way for me to know what version of the app is deploying easily when using continuous deployments via things like GitHub actions.

The `fly` CLI tool gives me a nice version/release that gets created each time (ie messages like `v81 deployed successfully`). It would be fantastic if this was supplied to the deployments as well so it can easily be printed via logs or something.

Thanks for fly though! Its absolutely fantastic and a real joy to deploy apps to!

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [June 8, 2021, 12:52am UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/2 "2021-06-08T00:52:17Z")

</div>

This is tricky for reasons you shouldn’t have to worry about!

Are you just trying to get a sense of what code is running? I know several people set an env variable from a git revision at deploy time. If that’s helpful, you can run something like:

`fly deploy -e GIT_REVISION=$(git rev-parse --short HEAD)`

We could almost just do this by default, I guess! It would make some sense to have that happen magically.

---

<div class="post-metadata">

**Author:** ![jsierles](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jsierles/32/595_2.png) [@jsierles](https://community.fly.io/u/jsierles)\
**Post date:** [June 8, 2021, 3:10am UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/3 "2021-06-08T03:10:53Z")

</div>

This works - but with this approach you wouldn’t know if a release were generated by a secret being changed.

---

<div class="post-metadata">

**Author:** ![james](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/james/32/412_2.png) [@james](https://community.fly.io/u/james)\
**Post date:** [June 8, 2021, 10:51am UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/4 "2021-06-08T10:51:51Z")

</div>

The git commit is a good idea! As @jsierles mentions this doesn’t cover all situations but is a good middle ground for now.

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [June 8, 2021, 11:55pm UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/5 "2021-06-08T23:55:56Z")

</div>

Right! There can actually be releases that don’t restart VMs, so it’ll frequently change in a way that would put the environment variable out of sync.

We might be able to expose current version from an API, though, or even a DNS txt query. We can keep that updated at least!

---

<div class="post-metadata">

**Author:** ![CanRau](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/canrau/32/3722_2.png) [@CanRau](https://community.fly.io/u/CanRau)\
**Post date:** [September 24, 2021, 6:14am UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/6 "2021-09-24T06:14:54Z")

</div>

I found a way to get the version from the GraphQL endpoint, via `curl` or JavaScript `fetch`

Okay so at least the in Deno version works 😍  
It’s actually just JavaScript

```auto
fetch("https://api.fly.io/graphql", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer XXX", // Replace XXX with your Access Token
  },
  body: JSON.stringify({
    query: `
    query($appName: String!) {
      app(name: $appName) {
        currentRelease {
          version
          status
        }
      }
    }`,
    variables: {
      appName: "YOUR_APP_NAME",
    },
  }),
})
  .then((res) => res.json())
  .then((res) => console.log(res.data));

```

which results in:

```json
{
  app: {
    currentRelease: {
      version: 49,
      status: "succeeded"
    }
  }
}

```

🥳

Get your access token via:  
[Fly.io web dashboard](https://fly.io/dashboard/apps/), selecting **Account** ➡︎ **Settings** ➡︎ **Access Tokens** ➡︎ **Create Access Token**

The `curl` version

```bash
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer FLY_API_TOKEN" \
--data '{"query":"query($appName:String!){app(name:$appName){currentRelease{version status}}}","variables":"{\"appName\":\"FLY_APP_NAME\"}"}' \
https://api.fly.io/graphql

```

which results in a string

```auto
{"data":{"app":{"currentRelease":{"version":55,"status":"succeeded"}}}}

```

---

<div class="post-metadata">

**Author:** ![AaronT](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@AaronT](https://community.fly.io/u/AaronT)\
**Post date:** [May 25, 2022, 6:59am UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/7 "2022-05-25T06:59:15Z")

</div>

Is there any change on this?

It would be really useful to be able to get the build number or the git revision number. I know I can set an env var for GIT\_REVISION myself through the CLI, but it would be great to not have to add this myself as my deploy command is already long enough. 😉

---

<div class="post-metadata">

**Author:** ![AaronT](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@AaronT](https://community.fly.io/u/AaronT)\
**Post date:** [August 8, 2022, 7:48am UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/8 "2022-08-08T07:48:44Z")

</div>

The `flyctl info` command now has VERSION.

So you can modify your Dockerfile and pass

`--build-args BUILD_VERSION=$(flyctl info --app APP | grep 'Version' | tr -s ' ' | cut -d' ' -f4)`

---

<div class="post-metadata">

**Author:** ![vanderhoop](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/vanderhoop/32/4818_2.png) [@vanderhoop](https://community.fly.io/u/vanderhoop)\
**Post date:** [October 13, 2022, 2:22pm UTC](https://community.fly.io/t/supply-build-version-via-env-variable/1667/9 "2022-10-13T14:22:42Z")

</div>

I’m also curious if there’s any movement on the ability to pass env vars in a first-class fashion.

Git commits are frequently used to tie exceptions and performance metrics to specific SHAs, and most PaaS’s support passing them as env vars from CI/CD pipelines.
