Build

build-pkg:
  stage: package
  image: snapcore/snapcraft
  script:
    - snapcraft --version
    - snapcraft
    - ls -la
  artifacts:
    expire_in: 1 week
    paths:
      - *.snap

Publication

First, you need to get the access parameters into the file. (This can even be done inside a docker container.)

snapcraft login
snapcraft export-login snapcraft.login
base64 snapcraft.login

After that, you need to add in the CI settings - Settings - CI/CD and in the Environment variables category add a new key named SNAPCRAFT_LOGIN_FILE with the beard that the base64 command will produce.

Well, the most (un)interesting thing

deploy-snapcraft:
  stage: deploy
  image: snapcore/snapcraft
  when: manual
  dependencies:
    - build-pkg
  script:
    - mkdir .snapcraft
    - echo $SNAPCRAFT_LOGIN_FILE | base64 --decode --ignore-garbage > .snapcraft/snapcraft.cfg
    - snapcraft whoami
    - snapcraft push *.snap --release stable
  environment:
    name: production
    url: https://snapcraft.io/$CI_PROJECT_NAME
  only:
    - master