My challenge is to publish a python package to a feed (Azure DevOps / Artifacts) using Authentification by Token.
Let me share what I tried :
A - [Build pipeline] I build a python package without a problem. Then I obtain an artifact to publish :
A.1 : The obtained artifact :
A.2 : The content of .pypirc file :
[distutils]
Index-servers =
py-test
[py-test]
Repository = http://AZURE_DEVOPS_URL/_packaging/py-test/pypi/upload
B - [Release pipeline]
Before creating the release pipeline :
B.1 In artifacts, I have created a new feed named py-test
B.2 I created a service connexion using Authentification Token to connect to the repository (specified in the .pypirc file)
B.3 Now, how I specified my release pipeline ?
My release pipeline takes the artifact produced by the build pipline and executes these steps :
B.3.1 Twine authentificate
B.3.2 twine upload
The complete command is :
twine upload -r py-test --config-file=dist/.pypirc dist/*
Now when I run the release pipeline, I get this :
Logs :
the log message :
2023-07-20T12:17:00.7581410Z ##[section]Starting: Upload the package to the acrtifactory
2023-07-20T12:17:00.7751611Z ==============================================================================
2023-07-20T12:17:00.7751900Z Task : Command line
2023-07-20T12:17:00.7751977Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2023-07-20T12:17:00.7752075Z Version : 2.201.1
2023-07-20T12:17:00.7752159Z Author : Microsoft Corporation
2023-07-20T12:17:00.7752216Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2023-07-20T12:17:00.7752301Z ==============================================================================
2023-07-20T12:17:01.7494177Z Generating script.
2023-07-20T12:17:01.7588823Z Script contents: shell
2023-07-20T12:17:01.7594609Z twine upload -r py-test --config-file=dist/.pypirc dist/*
2023-07-20T12:17:01.7888075Z ========================== Starting Command Output ===========================
2023-07-20T12:17:01.8089352Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\DevopsAgents\LocalAgent\_work\_temp\f871e3b1-0997-4b62-a24f-8f72a4ca9cf5.cmd""
2023-07-20T12:17:02.3709133Z Uploading distributions to
2023-07-20T12:17:02.3710981Z http://AZURE_DEVOPS_URL/_packaging/py-test/pypi/upload
2023-07-20T12:17:02.4192345Z Traceback (most recent call last):
2023-07-20T12:17:02.4192724Z File "<frozen runpy>", line 198, in _run_module_as_main
2023-07-20T12:17:02.4192959Z File "<frozen runpy>", line 88, in _run_code
2023-07-20T12:17:02.4193174Z File "C:\Program Files\Python\Python311\Scripts\twine.exe\__main__.py", line 7, in <module>
2023-07-20T12:17:02.4197266Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\__main__.py", line 33, in main
2023-07-20T12:17:02.4199690Z error = cli.dispatch(sys.argv[1:])
2023-07-20T12:17:02.4200307Z ^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4200503Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\cli.py", line 123, in dispatch
2023-07-20T12:17:02.4223403Z return main(args.args)
2023-07-20T12:17:02.4224634Z ^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4225268Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\commands\upload.py", line 198, in main
2023-07-20T12:17:02.4226650Z return upload(upload_settings, parsed_args.dists)
2023-07-20T12:17:02.4226823Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4227033Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\commands\upload.py", line 127, in upload
2023-07-20T12:17:02.4227260Z repository = upload_settings.create_repository()
2023-07-20T12:17:02.4227431Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4227642Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\settings.py", line 329, in create_repository
2023-07-20T12:17:02.4227840Z self.username,
2023-07-20T12:17:02.4227984Z ^^^^^^^^^^^^^
2023-07-20T12:17:02.4228181Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\settings.py", line 131, in username
2023-07-20T12:17:02.4228404Z return cast(Optional[str], self.auth.username)
2023-07-20T12:17:02.4228564Z ^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4228843Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\auth.py", line 34, in username
2023-07-20T12:17:02.4229044Z return utils.get_userpass_value(
2023-07-20T12:17:02.4229276Z ^^^^^^^^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4229514Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\utils.py", line 248, in get_userpass_value
2023-07-20T12:17:02.4229750Z value = prompt_strategy()
2023-07-20T12:17:02.4229914Z ^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4230121Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\auth.py", line 85, in username_from_keyring_or_prompt
2023-07-20T12:17:02.4230353Z return self.prompt("username", input)
2023-07-20T12:17:02.4231715Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4231926Z File "C:\Program Files\Python\Python311\Lib\site-packages\twine\auth.py", line 96, in prompt
2023-07-20T12:17:02.4232290Z return how(f"Enter your {what}: ")
2023-07-20T12:17:02.4232453Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-07-20T12:17:02.4232617Z EOFError: EOF when reading a line
2023-07-20T12:17:02.5155575Z ##[error]Cmd.exe exited with code '1'.
2023-07-20T12:17:02.5514398Z ##[section]Finishing: Upload the package to the acrtifactory
When I see this, I don't understand why the twine authentificate is not enough, why should I submit username/password?
Question : How can I make my release pipeline working with the Token Authentification to avoid displaying my username/password in pypirc?
Thanks in advance for your help!




