Mentioning it here in case it helps anyone else - when using Snapcraft 7 or later, it seems the SNAPCRAFT_STORE_CREDENTIALS
env var and the snapcraft login
command are mutually exclusive forms of authentication. In other words, if you’ve exported your credentials via snapcraft export-login
and have set the env var with those contents, then you do not need to run snapcraft login
(in fact you shouldn’t, because you’ll get the
Cannot login with 'SNAPCRAFT_STORE_CREDENTIALS' set.
Recommended resolution: Unset 'SNAPCRAFT_STORE_CREDENTIALS' and try again.
error if you try to).
In my case, I was adapting a previous login flow that used to work for Snapcraft 6, where the credentials were exported to a file and then passed to the snapcraft login
command via the --with
flag. For Snapcraft 7, at first I was under the impression that I needed to change that to export SNAPCRAFT_STORE_CREDENTIALS=$(cat <credentials-filename>)
and then run snapcraft login
without the --with
flag. But that was wrong and led to the error above; in fact I needed to set the env var and get rid of the snapcraft login
command altogether.
The docs here do technically say that (“There are currently two ways to use previously exported snapcraft credentials, either via an environment variable or by using snapcraft login --with
.”); however, further down is phrased a bit ambiguously: “In addition to the above, the snapcraft login
command accepts an additional --with
argument to reference a login credentials file” - this makes it sound like snapcraft login
accepts --with
in addition to the env var, which is not the case.
It might be worth explicitly clarifying on this page that the env var and snapcraft login
are two separate forms of authentication and only one should be used at a time (and perhaps the error message could call this out as well).