Using environment variables in `source:`

Hello all,

I am using the dump plugin to package an archive. The build process that creates this archive creates separate build folders for each machine architecture I am targeting.

Is it possible to specify a environment variable to the source: element?

      - BUILD_DIR: build          # hardcoded to build at the moment but I would like it to be dynamic eventually
    override-pull: |
      echo $BUILD_DIR          # prints "build"
      snapcraftctl pull            # will fail as it cannot resolve the `source:` element below
    source: $BUILD_DIR/package/LogAggregator-
    source-type: tar

You cannot use environment variables in the source directive. You can achieve the goal of utilising separate folders per architecture by writing your source directive similar to below:

    ... # the rest of your part
      - on amd64: path/to/amd64.tar.gz
      - on armhf: path/to/armhf.tar.gz
      - on arm64: path/to/arm64.tar.gz

Thanks @lucyllewy,

I don’t think that will help as I’m cross compiling so everything will be on amd64

Do you have any other suggestions? I would like to leave changing my pipeline as a last resort.



Can override-pull be used to effectively make the source dynamic? That is don’t specify source at all?

for example the file will not only have differently named build folders but have a version in the file name as well.

for example…



overide-pull: |
  steps to copy dynamically named file go here?
source: null

I’m unsure exactly how this works because I’ve never done cross compilation, but there’s a variation of on called to, where it operates based on the specified target architecture instead of the host.

So based on Dani’s example above

    ... # the rest of your part
      - to amd64: path/to/amd64.tar.gz
      - to armhf: path/to/armhf.tar.gz
      - to arm64: path/to/arm64.tar.gz

If that doesn’t help, you could use override-pull, the trick is you need to extract the .tar.gz into $SNAPCRAFT_PART_SRC, so you’d have some combination of e.g wget source and tar xf --strip-components 1 $SNAPCRAFT_PART_SRC. The key bit would be to avoid including snapcraftctl pull to prevent the default logic Assuming you’re on core20, the build step should then work just fine with the normal plugins. On Core / Core18, I’d presume similar but there may be some more complications with specific plugins.