Building and pushing snap packages from GitLab

Hi

Maybe this information could be useful on documentation. Since there is no support for GitLab on build.snapcraft.io, you can use the following:

  1. Login into snapcraft, create a credential file, convert in base64 and copy to clipboard

    snapcraft login
    snapcraft export-login snapcraft.login
    base64 snapcraft.login | xsel --clipboard
    
  2. Set GitLab-CI variable with your credentials

  • Go to your project Settings - CI / CD
  • on Environment Variables, add SNAPCRAFT_LOGIN_FILE with your credentials from the clipboard
  • click on Save variables
  1. create or edit a file in your project root folder called .gitlab-ci.yml with the following content (you can edit as you need)

    staging:
      image: ubuntu:18.04
      type: deploy
      script:
        - apt-get update -qy
        - apt-get install -y snapcraft 
        - snapcraft
        - echo $SNAPCRAFT_LOGIN_FILE | base64 --decode --ignore-garbage > snapcraft.login
        - snapcraft login --with snapcraft.login
        - snapcraft push *.snap --release edge
      only:
        - master
2 Likes

Hello Jonata,

Just adding a reference here to these other topics:


https://forum.gitlab.com/t/use-snapcraft-in-ci/37048
on how to do the build stage properly in 20.04 now that snapcraft is distributed as a snap instead of a deb.

1 Like