Can use env value from shell?

we want to use snapcraft in the CI. we have makefile and there has CC_VER=0.1.2, how can i use the CC_VER and set the version to CC_VER in snapcraft.yaml.

You can use the environment: keyword. See this topic:

Reading the original post this looks more like an env var you would set at build time …

AFIAK the environment: keyword only works inside the apps: area or at the toplevel of snapcraft.yaml but not for specific parts: entries, there you might have to use override-build:| with an export statement and call snapcraftctl build after it.

1 Like

Unfortunately that doesn’t work. snapcraftctl will create a new environment so any exports you do in the override script get lost. The only way to do this is to recreate the entire build step in procedural code in override-build :frowning:

1 Like

@sergiusens Is there no way to pass variables to the make plugin? This is not necessarily about the environment, as make can take such variables as build-time parameters.

Yes, variables as parameters is possible, and to be clear, if the intention is a resulting:

make MYVAR=VALUE

The this is currently possible by using make-parameters, such that to get the intended result you would do:

parts:
    make-part:
        source: .
        plugin: make
        make-parameters:
            - MYVAR=VALUE

This is documented on https://docs.snapcraft.io/reference/plugins/make or by running snapcraft help make. We could add an example like this to make it more clear though.

2 Likes