I’m trying to upload a package to pypi using a Gitlab CI job, but I cannot make it work :/ Anyone has a working example?
What I have tried so far in my .gitlab-ci.yaml
(from my local machine all of them are working):
Twine with a
.pypirc
fileJavaScriptx12121- echo "[distutils]" >> ~/.pypirc
2- echo "index-servers =" >> ~/.pypirc
3- echo " pypi" >> ~/.pypirc
4- echo "" >> ~/.pypirc
5- echo "[pypi]" >> ~/.pypirc
6- 'echo "repository: https://upload.pypi.org/legacy/" >> ~/.pypirc'
7- 'echo "username: ${PYPI_USER}" >> ~/.pypirc'
8- 'echo "password: ${PYPI_PASSWORD}" >> ~/.pypirc'
9- python3 setup.py check sdist bdist # This will fail if your creds are bad.
10- cat ~/.pypirc
11- twine upload dist/* --config-file ~/.pypirc
12
Same as before but with
$VARIABLE
JavaScript151[ ]
2- 'echo "username: $PYPI_USER" >> ~/.pypirc'
3- 'echo "password: $PYPI_PASSWORD" >> ~/.pypirc'
4[ ]
5
Two options before but using
python setup.py ... upload
twine upload dist/* -u $PYPI_USER -p $PYPI_PASSWORD
twine upload dist/*
wihtTWINE_USERNAME
andTWINE_PASSWORD
environment variables.
… and always get a 403 Client Error: Invalid or non-existent authentication information
. I’m running out of options…
Advertisement
Answer
I got this working, using a modified version of your code:
JavaScript
1
17
17
1
pypi:
2
stage: upload
3
script:
4
- pip install twine
5
- rm -rf dist
6
- echo "[distutils]" >> ~/.pypirc
7
- echo "index-servers =" >> ~/.pypirc
8
- echo " nexus" >> ~/.pypirc
9
- echo "" >> ~/.pypirc
10
- echo "[nexus]" >> ~/.pypirc
11
- echo "${PYPI_REPO}" >> ~/.pypirc
12
- echo "${PYPI_USER}" >> ~/.pypirc
13
- echo "${PYPI_PASSWORD}" >> ~/.pypirc
14
- python3 setup.py check sdist bdist # This will fail if your creds are bad.
15
- python setup.py sdist bdist_wheel
16
- twine upload -r nexus dist/*.tar.gz
17
The difference is I didn’t use the “‘” and got rid of the colons in the yaml; instead I set the values of the secrets as e.g., username: myuser