Skip to content

recommend TESTPYPI_ID_TOKEN for releasing to TestPyPi in docs #19565

@Frederik-Hartmann

Description

@Frederik-Hartmann

Describe the bug

Publishing to TestPyPi with a trusted publisher (GitLab) does not work when following the documentation in
https://docs.pypi.org/trusted-publishers/using-a-publisher/#gitlab-cicd

The problem appears to be that you need to rename PYPI_ID_TOKEN to TESTPYPI_ID_TOKEN in .gitlab-ci.yml

I will make a PR with an update of the documentation shortly after this.

Expected behavior

A release to TestPyPi.

To Reproduce

shortened .gitlab-ci.yml

release-test-pypi:
[...]
  id_tokens:
    PYPI_ID_TOKEN:
      aud: testpypi
  script:
    - pip install -U twine
    - twine upload -r testpypi dist/* --verbose

I get the following output (shortened)

$ twine upload -r testpypi dist/* --verbose
Uploading distributions to https://test.pypi.org/legacy/
INFO     dist/your_python_package_1234-1.0.0-py3-none-any.whl (12.4 KB)         
INFO     dist/your_python_package_1234-1.0.0.tar.gz (10.0 KB)                   
INFO     username set by command options                                        
INFO     Querying keyring for password                                          
INFO     No keyring backend found                                               
INFO     Trying to use trusted publishing (no token was explicitly provided)    
ERROR    TrustedPublishingFailure: Unable to retrieve an OIDC token from the CI 
         platform for trusted publishing GitLab: Environment variable           
         TESTPYPI_ID_TOKEN not found 

After changing the YAML to

release-test-pypi:
[...]
  id_tokens:
    TESTPYPI_ID_TOKEN:
      aud: testpypi
  script:
    - pip install -U twine
    - twine upload -r testpypi dist/* --verbose

the release to TestPyPi is successful.

My Platform

I ran the test release in a GitLab protected environment using python:3.13-slim as an image. The build was done with Hatch.

Additional context

TLDR: use TESTPYPI_ID_TOKEN instead of PYPI_ID_TOKEN for trusted publishing with GitLab.

I have added a small comment to the docs and will create a PR now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛requires triagingmaintainers need to do initial inspection of issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions