1

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

Dibyendu Dey
  • 349
  • 2
  • 16
  • 1
    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 https://stackoverflow.com/questions/63117797/azure-pipelines-is-there-a-way-to-view-the-folder-structure – Kontekst Jul 20 '21 at 08:13
  • Great idea! I tried and finding the files are in the folder. – Dibyendu Dey Jul 20 '21 at 15:39

2 Answers2

3

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

Dibyendu Dey
  • 349
  • 2
  • 16
0

Indentation before CopyFiles@2 enter image description here

Kontekst
  • 946
  • 8
  • 17
  • that is probably why CopyFiles does not copy files to D:/A/1/A according to your screenshot https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml – Kontekst Jul 20 '21 at 16:55
  • And indentation in PublishBuildArtifacts after inputs: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops – Kontekst Jul 20 '21 at 16:56
  • Actually yml was so long I had to chop it to paste in stackoverflow. Indentation was due to copy-paste issue. That error is gone now after I remove `SourceFolder: '$(Build.SourcesDirectory)'` in `CopyFiles2` and let it pick default. I'm getting my build. But I still can't see it in Artifacts (expected to see the build there) – Dibyendu Dey Jul 20 '21 at 17:13
  • 1
    I have done example repo with working example can you take a look if everything is similar to yours? https://dev.azure.com/tomaszkontek/FeaturesTesting/_git/TestCopyFiles?path=%2Fazure-pipelines.yml | https://dev.azure.com/tomaszkontek/FeaturesTesting/_build/results?buildId=72&view=results https://dev.azure.com/tomaszkontek/FeaturesTesting/_build/results?buildId=72&view=artifacts&pathAsName=false&type=publishedArtifacts – Kontekst Jul 20 '21 at 17:38
  • Nice. I see your also showing `published` which is same state as mine. But when I visit the `Artifacts` tab, I was expecting to see that published package there. Is it wrong expectation? – Dibyendu Dey Jul 20 '21 at 17:43
  • I am sorry I misunderstood the case, PublishBuildArtifacts@1 can not publish artifacts to the Artifacts Feed – Kontekst Jul 20 '21 at 17:53
  • 1
    Then Twine needs to upload your artifacts, are you sure that is should contain dist/*.whl parameter and not something like "build"? – Kontekst Jul 20 '21 at 17:57
  • 1
    Artifacts published by PublishBuildArtifacts@1 are used for CI/CD, and used then in another stages/releases/pipelines Meanwhile artifacts published to Artifacts feed can be used for example as Nuget/Python/Maven packages to be downloaded from there. – Kontekst Jul 20 '21 at 18:58