https://discord.umbraco.com logo
#help-with-umbraco
Displaying Git sha as a build id on site with Umbraco Cloud
# help-with-umbraco
u

2lach

02/03/2024, 7:51 AM
Hey everybody I have an idea: In short, I want to display the latest Git SHA in the footer for version tracking. Thats the what. So i started trying out some implementations and this led me down into git hooks land, Trying to commit the latest Git SHA within the current commit proved challenging, like locking a door and tossing in your keys, yielding interesting but unworkable results. So i decided to take a different approach. In my `UmbracoProject.csproj`i added:
Copy code
xml
  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
      <Exec Command="git rev-parse HEAD > $(ProjectDir)properties\commit.txt" />
  </Target>
I found a nifty solution (imo). Instead of attempting to commit a file with the latest Git SHA, I now generate it in a file called
commit.txt
during the build process. This way, I can easily parse and display the value. I've also added the file to
.gitignore
locally to prevent Git conflicts. That the how This worked smoothly on my local setup, but on Umbraco Cloud, it posed challenges. As a Mac/Linux user, I'm not well-versed in Windows servers. While exploring Kudu tools, I discovered that significant changes occur between pushing my code to Umbraco Cloud and its deployment, including alterations to the entire file structure. Despite performing a thorough PowerShell search on the server's hard drive, my "commit.txt" file was nowhere to be found. Thats the WTF So my question is When creating a file on the fly containing the latest Git SHA value, where can I store it so it's reachable (on the win server) and there is a const/absolute path I can use to parse the value? > It doesn't have to work locally but should always work from my Umbraco cloud server That's the question Thanks for reading any helpful advice is most welcome 👍 PS I know this can be solved with CI/CD pipelines and injecting the git sha as an env var, but honestly i don't want to rebuild the entire CD/CI process just to display a git sha.
a

Ambert

02/03/2024, 12:09 PM
Could perhaps work if you put the file in the wwwroot folder
As i believe thats the only publicily available part
u

2lach

02/03/2024, 5:28 PM
Thanks will try that 👍
@Ambert Thanks for the advise, that worked great https://gist.github.com/2lach/3431900cf27b6f902654c6b1cc178785
a

Ambert

02/03/2024, 7:44 PM
Good to hear @2lach ! 😄
Happy coding!