Score:2

How do you display a version number on a footer file?

cn flag

When I deploy my Drupal code, I build an artifact with BLT. I would like to write a file of some kind with the version number (tag provided to the artifact) that could then be read and displayed in the footer.

Where is the best place to write this file in a Drupal directory?

What is the best method to read from the file and display on the page safely?

Is there a different/better method altogether that I'm not thinking of?

Score:3
in flag

One way I do it is to commit a text file and then check that live. This can be done while building the project in CI. Here is an example (note your CI variables may vary):

In one of the final steps before the artifact deploys to the server, you can do:

deploy:
    - echo $CI_COMMIT_TAG > path/to/drupal/docroot/themes/custom/yourtheme/version.txt
    - git add/commit steps...
    - git push ...

Then visiting that URL in the browser will tell you what 'version' that is, made from your CI variable.

shelane avatar
cn flag
That gets me 90% of the way. A few tweaks for my particulars and it should be good. Thanks.
shelane avatar
cn flag
I have added a preprocess function for my page template to read the contents of this page and display in the footer. `$variables['version'] = file_get_contents(DRUPAL_ROOT . '/../version.txt');` And then my Jenkins function is writing to the file from the passed in parameter of the version and committing. No need to push in my case as it will be in the artifact and not need to be in the master branch itself.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.