Source-tag or source-commit - via variable?

Is there any way to use a variable for defining the source-tag or source-commit for a part in the snapcraft.yaml -file?

I have a repo, which provides multiple applications/commands and thus I probably should have multiple parts as well. I would very much prefer to keep the parts/applications in sync and if I use a manually written tag - I’m quite sure it will sooner or later be out-of-sync.

So, is it possible to have a definition somewhere and then re-use that via all the parts?

Like PE-UTILS-VER="2.1.0" and then just update that once and use that same variable in the snapcraft.yaml in multiple places?

      plugin: nil
      source-tag: $PE-UTILS-VER

I could not find anything straight off the bat in the documents.

Another idea to work around this - can I just have 3 parts there, of which 1 does the pull and the others just have to run AFTER the part that does the git fetch and just refer to that some location somehow?

You’re right, there is no easy solution here. Yaml does not support variable placeholders and snapcraft does not add this functionality.

You have a few options. Your idea of using the after keyword and copying another part’s staged directory could work, but it would take some experimenting.

Another option would be using the override-pull keyword to work around yaml’s lack of variables:

override-pull: |
  craftctl default
  git checkout $(cat snap/my-part-version.txt)

The last option would be to use override-pull to be dynamic. Often, it’s used to pull the latest tagged release by parsing commands like git tag -l or git describe --tags.