Understanding deployment with nuget

oliver's Avatar

oliver

30 Jun, 2018 07:34 AM

Hey.

I want to try if - and how - I can use AppVeyor's Deployment (with NuGet) to publish a Powershell module to the Powershell Gallery.

From what I understand from reading https://www.appveyor.com/docs/deployment/nuget/, this should be easily achievable with the deploy block in appveyor.yml.
However, as PowerShellGet has a command for publishing a module (Publish-Module), I am unaware of what happens under the hood to construct the package.

Did anyone try this before?
Does anyone have some tips for me?

  1. Support Staff 1 Posted by Ilya Finkelshte... on 04 Jul, 2018 03:59 AM

    Ilya Finkelshteyn's Avatar

    I see that people who publish PowerShell module do everything simple with Publish-Module. If you search GitHub for appveyor.yml Publish-Module you can find a lot of samples. Just store API key as a secure variable.

    Please let me know if I understand your question correctly and this helps. If not, please elaborate your scenario with more details.

  2. 2 Posted by oliver on 04 Jul, 2018 06:00 AM

    oliver's Avatar

    Thank you for the reply, Ilya.

    I currently use that command as well (but in the build script instead of the appveyor.yml).
    What I am analyzing is: would I benefit from using AppVeyor's deploy over having a script upload the nuget bits.

  3. Support Staff 3 Posted by Ilya Finkelshte... on 04 Jul, 2018 07:53 AM

    Ilya Finkelshteyn's Avatar

    You will see nice deployment history under Deployments tab. Also if you use Environment deployment, you can re-deploy the same bits multiple times separately from build process.

    You will be needed to package your module as a .nupkg file (this part I have no knowledge about, but I believe it is doable). Then save it as an artifact so it can be deployed by Nuget provider.

    Regarding Nuget provider internals, it is using Nuget.Core, not nuget.exe under the hood.

  4. 4 Posted by oliver on 04 Jul, 2018 04:20 PM

    oliver's Avatar

    Perfect.
    I imagine I can put the logic to create the Nugget package in the pre-deploy block as a Powershell script and that pre-deploy block will be executed every time I deploy.

    Is that so?
    Or would once the package is added as artifact be persisted? If so, the Powershell code to create the package is no longer necessary. Is this managed automatically in the pre-deploy block, I must I test this myself in the code?

  5. Support Staff 5 Posted by Ilya Finkelshte... on 04 Jul, 2018 06:00 PM

    Ilya Finkelshteyn's Avatar

    Sorry I did not understand the second part... Can you please elaborate? Maybe you could do some small experiment and provide a YAML sample?

    Generally speaking any AppVeyor built-in deployment requires an artifact (not just a file on local disk of build VM). So you need to choose what file you need to deploy and publish it as artifact. After that you can re-use the same artifact (with the same version of bits) multiple time. But for new bits you need to package new artifact...

  6. 6 Posted by oliver on 05 Jul, 2018 07:13 AM

    oliver's Avatar
    version: 1.0.{build}
    
    image: Visual Studio 2015
    
    pull_requests:  
      do_not_increment_build_number: true
    
    init:  
      - ps: |
          if (-not ($env:PowershellVersion)) {$env:PowershellVersion = "5.1"}
          if (([version]$env:PowershellVersion).Major -ge 6) {$env:posh = "pwsh"} else {$env:posh = "powershell"}
          Add-Content (Join-Path $Home ".git-credentials") "https://$($env:access_token):x-oauth-basic@github.com`n"
      - git config --global credential.helper "store --file ~/.git-credentials"
      - git config --global user.email "[email blocked]"
      - git config --global user.name "AtlassianPS automation"
    
    install:  
      - ps: '& $env:posh -File "./Tools/setup.ps1"'
    
    build_script:  
      - ps: '& $env:posh -Command "Invoke-Build"'
      # This performs the following actions:
      #  - build source
      #  - run tests against result of build
      #  - creates a zip from release
      #  - create nupkg for deployment
    
    artifacts:  
      - path: '**\*.nupkg'
      - path: '**\*.zip'
    
    before_deploy:  
      # Test if this should deploy
      #     we don't want to deploy anything that is not on master
      - ps: '& $env:posh -Command "Should this deploy??"'
    
    deploy:  
      - provider: NuGet
        server: https://my.nuget.server/feed
        api_key:
          secure: FYWX6NfjZIVw==
        skip_symbols: false
        symbol_server: https://your.symbol.server/feed
        artifact: MyPackage.nupkg
    
      - provider: GitHub
        artifact: /.*\.zip/
        draft: false
        prerelease: false
        on:
          branch: master
          appveyor_repo_tag: true
    <pre><code>
    I want `deploy` only to be executed when on branch `master`.
    I would write a PS script in `before_deploy` to test this.
    But what kind of code would `before_deploy` have to execute to skip `deploy` without failing the build job?
    
    How can I make the `artifacts` dependent on how the branch?
    My goal is to set this up so that nothing apart from `master` can be deployed</code>
    </pre>
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac