0
votes

A. Used twine to authenticate and publish my Python packages to an Azure Artifacts feed

     - task: CmdLine@2
        displayName: Build Artifacts
        inputs:
          script:
            echo Building distribution package
            python -m pip install --upgrade twine build setuptools
            python -m build 
      
      - task: TwineAuthenticate@1
        inputs:
          artifactFeed: ddey-feed
      - script:
          python -m twine upload -r "ddey-feed" --config-file $(PYPIRC_PATH) dist/*.whl

B. Although it ran successfully, but I didn't get any package in Artifacts. I found the Warning:'D:\a\1\a' is empty. Nothing will be added to build artifact

C. I did some research and decided to add additional section which does a copy and publish

          - task: CopyFiles@2
           displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
           inputs:
            SourceFolder: '$(Build.SourcesDirectory)'
            Contents: |
              **/*
              !.git/**/*
            TargetFolder: '$(Build.ArtifactStagingDirectory)'
           condition: succeededOrFailed()
    
          - task: PublishBuildArtifacts@1
            displayName: 'Publish Artifact: drop'
            inputs:
            PathtoPublish: '$(build.artifactstagingdirectory)'
            condition: succeededOrFailed()

Can anyone please comment what else I can modify in yaml file to get the package available in Artifacts?

Different Tried things after Suggestions:

  1. Add Tree command to see all build folders to confirm generation of file:

enter image description here

2. After removing source folder and let it use default source enter image description here

successful build and consumed: enter image description here

Artifacts is generated and I can see it from pipeline. enter image description here

Problem Statement

In Artifacts tab, I don't see the build available in any feed. How to connect the build with a specific feed (ddey-feed). I though TwineAuthenticate is suppose to take care of it.

enter image description here

2
Did you check if in your $(Build.SourcesDirectory) contains any files and then after copy if any files are in $(Build.ArtifactStagingDirectory)? Here you have how to check it stackoverflow.com/questions/63117797/…Kontekst
Great idea! I tried and finding the files are in the folder.Dibyendu Dey

2 Answers

2
votes

ok. I have finally resolved the whole issue and could deploy the package to Artifacts Feed.

Key learning:

  • When creating Artifacts Feed, Make sure to check permission. Add Allow project-scoped builds otherwise will get permission error in pushing package from Azure pipeline
  • You need to define PYPIRC_PATH to point where .pypirc file reside. This can be done using environment variable set-up as shown below
- script: |
   echo "$(PYPIRC_PATH)"
   
   python -m twine upload -r ddey-feed --verbose --config-file $(PYPIRC_PATH) dist/*
  displayName: 'cmd to push package to Artifact Feed'
  env:
    PYPIRC_PATH: $(Build.SourcesDirectory)
  • Make sure Twine Authenticate feed name matches with twine upload feed name. If pipeline fails to push the package, you can try to run following command directly from your repo: twine upload -r ddey-feed --config-file ./.pypirc dist/ and it should successfully upload the build to Artifacts.

  • For debug purpose, print the directories.

    echo "Structure of work folder of this pipeline:"
    
    tree $(Agent.WorkFolder)\1 /f
    
    echo "Build.ArtifactStagingDirectory:" 
    
    echo "$(Build.ArtifactStagingDirectory)"
    
    echo "Build.BinariesDirectory:" 
    
    echo "$(Build.BinariesDirectory)"
    
    echo "Build.SourcesDirectory:"
    
    echo "$(Build.SourcesDirectory)"
    
  • Summary of components of the pipeline

enter image description here

0
votes

Indentation before CopyFiles@2 enter image description here