Before you start
- Use a disposable TestPyPI project you can administer and a GitLab.com project. PyPI trusted publishing requires GitLab.com for this workflow.
- Have the repository namespace, project name and top-level pipeline file. If you use a release environment, use its exact name in both the publisher settings and job.
- Check GitLab availability
- Check PyPI availability
Data and access
Who does what
Setup steps
Register the publisher on TestPyPI
Add a trusted publisher in the TestPyPI project settings. Register the GitLab namespace, project name and top-level pipeline file, plus the release environment if the job uses one.
Check. TestPyPI’s project settings list the namespace, project and pipeline file from your test run, plus the environment if configured.
Run the publishing job
Follow PyPI’s GitLab workflow instructions with TestPyPI as the target. Review who can change the pipeline and trigger the publishing job.
Check the registry before the GitLab job runs - Token request
- For the rehearsal, request a GitLab identity token for the testpypi audience and use the TESTPYPI_ID_TOKEN name in PyPI’s GitLab example.
- Upload destination
- Choose the testpypi repository in Twine. The GitLab job should upload to test.pypi.org.
- Production destination found
- If the token audience is pypi or the upload targets pypi.org, stop the rehearsal and correct the job before running it.
Check. The publishing job completes against TestPyPI. The job and pipeline link identify the intended test revision.
Verify the package version
Check that TestPyPI shows the expected version and that the job ran for the intended commit. Review the configuration before applying the same controls to the production project.
Check. The test registry lists the exact version produced by that revision. Open the version page instead of relying on the pipeline status alone.
Check your result
PyPI documents this GitLab publisher for GitLab.com projects. Keep the publishing identity separate from any KeySigner approval used by a maintainer.
If you get stuck
TestPyPI rejects the publishing identity
Confirm that the TestPyPI publisher names the GitLab.com namespace, project, top-level pipeline file and environment that ran. Check that the job requested an identity token for the target registry.