Search code examples
dockergitlabgitlab-cigitlab-ci-runnersentry

Authenticate sentry-cli inside docker in gitlab ci


I want to run sentry-cli inside my docker image like this:

sentry-frontend:
  stage: sentry
  services:
    - docker:18-dind
  before_script:
    - docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" registry.xxx.xx
  script:
    - export SENTRY_AUTH_TOKEN=xxxxxxxxxxxxxxxxxx
    - export IMAGE=$CI_REGISTRY_IMAGE/frontend-builder:$CI_COMMIT_REF_NAME
    - export RELEASE_VERSION=$CI_COMMIT_REF_NAME
    - docker pull getsentry/sentry-cli
    - docker run --rm -v $(pwd):/work getsentry/sentry-cli releases -o org -p frontend new $RELEASE_VERSION

  tags:
    - dind

However the job fails because

error: API request failed caused by: sentry reported an error: Authentication credentials were not provided. (http status: 401)

I tried:

- docker run --rm -v $(pwd):/work getsentry/sentry-cli --auth-token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

however after that I get the same message as I would if I ran

docker run --rm -v $(pwd):/work sentry-cli --help

and after that it fails as if the command was not correct.I can't seem to find any information on how to do that correctly either. How to provide credentials inside that image?


Solution

  • If you want to pass the SENTRY_AUTH_TOKEN environment variable to the container, you can adapt your docker run command like this:

    docker run --rm -v "$PWD:/work" -e SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" getsentry/sentry-cli releases -o org -p frontend new $RELEASE_VERSION
    

    or more concisely:

    docker run --rm -v "$PWD:/work" -e SENTRY_AUTH_TOKEN getsentry/sentry-cli releases -o org -p frontend new $RELEASE_VERSION
    

    (but note that the latter version won't work if docker is an alias of sudo docker)

    The relevant documentation page is: docs.docker.com/engine/reference/commandline/run/

    As an aside, note that -v "$PWD:/work" is more efficient than -v "$(pwd):/work" (one less process to spin).