0
votes

I have been having issues with sending build artifacts to my feed and can't figure out where my issue is at.

I forked over this repository from an Azure document since I am new to this and learning to create a CI/CD pipeline (https://github.com/Azure-Samples/python-docs-hello-world).

With the twine or universal package publishing setup guides there are steps for connecting to the feed such as creating a .piyrc file in your home directory but is that done locally or somewhere within the pipeline YAML?

Universal Publishing YAML

steps:
- task: UniversalPackages@0
  displayName: 'Universal publish'
  inputs:
    command: publish
    vstsFeed: 'cd75ead1-7beb-42f9-9477-e958501bb986'
    publishDirectory: '$(Pipeline.Workspace)'
    vstsFeedPublish: 'cd75ead1-7beb-42f9-9477-e958501bb986'
    vstsFeedPackagePublish: drop

Twine Method

twine upload -r {Feed} --config-file $(PYPIRC_PATH) $(Pipeline.Workspace)

With Universal Publishing I receive an error about the path provided as being invalid.

With Twine I get an error about InvalidDistribution: Cannot find file (or expand pattern)

The $(Pipeline.Workspace) that I have written above was created as a path in my build pipeline to copy all files over from an Archive step. I see the artifact being made in the build pipeline and then downloaded in the first step of the release pipeline so I'm not sure what is going on or if it's something as simple as using the incorrect path.

1
Hi @ubiquitinoob44. Is there any update about this ticket? You could check if the answer could give you some help. Feel free to let me know if you have questions. Just a remind of this.Kevin Lu-MSFT
@KevinLu-MSFT Hi sorry just got around to checking this out. I tried and it failed on the python script stating "python: can't open file 'setup.py': [Errno 2] No such file or directory " also Bash exited with code '2'rk92
Don't worry, this is because there is no setup.py file in your repo. You could try this sample repo :)Kevin Lu-MSFT
@KevinLu-MSFT Thanks so much that new repository worked and I see a package in my Artifact Feed now. One additional thing was I originally had a "User lacks permission error. You need to have AddPackage" To fix this click Artifacts > Select feed in drop down > Feed settings icon on the right > Permissions > 3 Ellipses on the right > Allow project scoped builds.rk92
@KevinLu-MSFT So was the main issue that the original repo did not have the setup.py file only? Could I add that just to see if it would work into the repo?rk92

1 Answers

1
votes

With Twine I get an error about InvalidDistribution: Cannot find file (or expand pattern)

You need to specify the specific artifacts path instead of using the $(Pipeline.Workspace).

The $(pipeline.workspcae) is equal to the $(Agent.BuildDirectory). You could refer to this doc.

From the Github link, it seems that you want to publish a python package to feed.

You could refer to the following steps to create CI\CD.

In CI , you could Build sdist and publish the artifact to pipeline.

Here is the sample:

steps:
- task: UsePythonVersion@0
  displayName: 'Use Python 3.6'
  inputs:
    versionSpec: 3.6

- script: 'python setup.py sdist'
  displayName: 'Build sdist'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: dist'
  inputs:
    PathtoPublish: dist
    ArtifactName: dist

In CD , you could set the build artifacts as resource and use twine to upload the python package to feed.

Here is an example:

enter image description here

twine upload -r AzureTest23  --config-file $(PYPIRC_PATH) D:\a\r1\a\{Source alias}\dist\*

The twine authenticate task could give the $(PYPIRC_PATH) variable.

If you want to determine your correct path, you can find it in the release log.

enter image description here

Note: If there are spaces or special characters in the path, they need to be escaped in cmd, otherwise they will not be recognized.

The name relates with the source alias, you could change it in artifacts source.

enter image description here

By the way, if you use the Universal Publish task, you also need to give the correct path.