Snapcraft Login issue - Azure pipeline

Hello there,

I’m trying to upload a snap to the snapstore using the SNAPCRAFT_STORE_CREDENTIALS environment variable that holds the value of the authentication key. I do this from an Azure release pipeline in a command line task. This is my script :

set -x
snap version
lxd --version
sudo apt-get update
sudo snap install --classic snapcraft
sudo snap install multipass
export PATH="${PATH}:/snap/bin"
snapcraft --version
sudo snapcraft --debug --destructive-mode
sudo snapcraft upload my_app_3.1_amd64.snap --release=latest/beta --verbosity=trace

And this is the error I get :

craft-store error: No keyring found to store or retrieve credentials from.
Recommended resolution: Ensure the keyring is working or SNAPCRAFT_STORE_CREDENTIALS is correctly exported into the environment
For more information, check out:

When I try to use a keyring on a headless Linux system according to the documentation page : Snapcraft documentation. The execution blocks forever at the line

dbus-run-session -- sh

displaying this error

dbus[3496]: Unable to set up transient service directory: XDG_RUNTIME_DIR "/run/user/1001" is owned by uid 1001, not our uid 0

How can I avoid this error.

And according to the documentation, the next command is :

gnome-keyring-daemon --unlock

which can be unblocked by typing the password and CTRL+D which is not possible using a CI/CD pipeline…

How is it supposed to be done ?

Thanks for your help !

This is my configuration

    snap    2.57.2
    snapd   2.57.2
    series  16
    ubuntu  20.04
    kernel  5.15.0-1022-azure
    lxd --version
    snapcraft --version

How did you generate your store credentials that you have saved in the $SNAPCRAFT_STORE_CREDENTIALS variable? Also how long ago? The format has changed since Snapcraft 7.0 which requires regenerating the credentials.

I generated them on an Ubuntu server 22 using snapcraft 7.2.7 5 days ago.

Oh, I see your problem. You’re using sudo. When you run a command through sudo the environment will not be forwarded by sudo to the command that you are running as root (or another user). The snapcraft upload command doesn’t need to be run as root, unless the snap package file is not readable by the normal user (although you can fix the permissions).

So try not using sudo:

snapcraft upload *.snap --release=latest/beta

If there is a permission issue with the *.snap file then you can fix that with:

sudo chmod +r *.snap


sudo chown $USER *.snap

As a last resort if you are set on using sudo you can forward the environment like this:

sudo --preserve-env=SNAPCRAFT_STORE_CREDENTIALS snapcraft upload *.snap --release=latest/beta

It worked ! Thank you so much for your help !