skip to Main Content

We’re using snapcraft snaps to publish our software. We have a classic pipeline step for logging into snapcraft, one for releasing the snap and one for logging out. However, we’re unable to release the snap because the agent loses the context between logging in and releasing and thus can’t release the snap.

1st step:
export SNAPCRAFT_STORE_CREDENTIALS=$(cat $(Agent.TempDirectory)/[OUR-EXPORTED-LOGIN])

2nd step:
snapcraft release [SNAPNAME] "$(Revision)" "candidate"

3rd step:
unset SNAPCRAFT_STORE_CREDENTIALS

So in the second step we’re getting:

Starting Snapcraft 7.5.2
craft-store error: No keyring found to store or retrieve credentials from.
Ensure the keyring is working or SNAPCRAFT_STORE_CREDENTIALS is correctly exported into the environment
For more information, check out: https://snapcraft.io/docs/snapcraft-authentication

If we instead place the contents of step 2 inside step 1 the command works as intended. This indicates to us that SNAPCRAFT_STORE_CREDENTIALS is unset between the steps. This is strange because ordinarily this only happens between jobs and not steps.

2

Answers


  1. Chosen as BEST ANSWER

    Thank you. I solved this by logging in and releasing in the same step. I checked with my boss and we both thought the legacy code wasn't best practice. We also had the tasks in a task group, so it was really easy to change.


  2. Because you only export SNAPCRAFT_STORE_CREDENTIALS in your first steps, so the visibility of this variable is task level.

    You can set a job-scoped variable from a script. To set a variable from a script, use the task.setvariable logging command. This doesn’t update the environment variables, but it does make the new variable available to downstream steps within the same job.

    For example, add this command in your first step if you are using a Command line task:

    echo "##vso[task.setvariable variable=SNAPCRAFT_STORE_CREDENTIALS]$(SNAPCRAFT_STORE_CREDENTIALS)"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search