I was facing a problem saying that the username got EOF. After some discussion, the present setup it works fine is:
In Settings/CI-CD/Variables. Add TWINE_USERNAME and TWINE_PASSWORD in your secret variables. Mark them as protected and masked. Obs.: See the rules for the values of those variables, such as no dots, greater than 8 chars and no special as said before.
In Settings/Repository/Protected Tags mark tags to be protected and add the regex of your tags.Tks to jaraco@github.
In addition go to Settings/Repository/Push rules and mark Prevent committing secrets to Git and
Do not allow users to remove git tags with git push to create a more secure environment.
Other related links:
- https://github.com/pypa/twine/issues/461
 - https://stackoverflow.com/questions/48681816/upload-to-pypi-from-gitlab-pipelines
 - https://gitlab.com/dpizetta/helpdev/blob/master/.gitlab-ci.yml
 
pypi_release:
  stage: deploy
  cache: {}
  script:
    - pip install -U twine
    - python setup.py sdist bdist_wheel
    - twine check dist/*
    # try upload in test platform before the oficial
    - twine upload --repository-url https://test.pypi.org/legacy/ dist/*
    - pip install --no-deps --index-url https://test.pypi.org/simple/ helpdev==$CI_COMMIT_TAG
    - pip uninstall helpdev -y
    # upload to oficial
    - twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
    - pip install helpdev==$CI_COMMIT_TAG
    - helpdev --version
    - pip uninstall helpdev -y
  only:
    - tags