tag:help.appveyor.com,2012-11-13:/discussions/questions/22160-understanding-deployment-with-nugetAppVeyor: Discussion 2018-08-29T21:46:46Ztag:help.appveyor.com,2012-11-13:Comment/455941172018-07-04T03:59:22Z2018-07-04T03:59:22ZUnderstanding deployment with nuget<div><p>I see that people who publish PowerShell module do everything simple with <code>Publish-Module</code>. If you search GitHub for <a href="https://github.com/search?q=appveyor.yml+Publish-Module&type=Code">appveyor.yml Publish-Module</a> you can find a lot of samples. Just store API key as a <a href="https://www.appveyor.com/docs/build-configuration/#secure-variables">secure variable</a>.</p>
<p>Please let me know if I understand your question correctly and this helps. If not, please elaborate your scenario with more details.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/455941172018-07-04T06:00:20Z2018-07-04T06:00:20ZUnderstanding deployment with nuget<div><p>Thank you for the reply, Ilya.</p>
<p>I currently use that command as well (but in the build script instead of the appveyor.yml).<br>
What I am analyzing is: would I benefit from using AppVeyor's <code>deploy</code> over having a script upload the nuget bits.</p></div>olivertag:help.appveyor.com,2012-11-13:Comment/455941172018-07-04T07:53:59Z2018-07-04T07:53:59ZUnderstanding deployment with nuget<div><p>You will see nice deployment history under <code>Deployments</code> tab. Also if you use <code>Environment</code> deployment, you can re-deploy the same bits multiple times separately from build process.</p>
<p>You will be needed to package your module as a <code>.nupkg</code> file (this part I have no knowledge about, but I believe it is doable). Then <a href="https://www.appveyor.com/docs/packaging-artifacts/">save it as an artifact</a> so it can be deployed by Nuget provider.</p>
<p>Regarding Nuget provider internals, it is using <a href="https://github.com/NuGet/NuGet2">Nuget.Core</a>, not <code>nuget.exe</code> under the hood.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/455941172018-07-04T16:20:11Z2018-07-04T16:20:11ZUnderstanding deployment with nuget<div><p>Perfect.<br>
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.</p>
<p>Is that so?<br>
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?</p></div>olivertag:help.appveyor.com,2012-11-13:Comment/455941172018-07-04T18:00:05Z2018-07-04T18:00:05ZUnderstanding deployment with nuget<div><p>Sorry I did not understand the second part... Can you please elaborate? Maybe you could do some small experiment and provide a YAML sample?</p>
<p>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...</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/455941172018-07-05T07:13:15Z2018-07-05T07:13:15ZUnderstanding deployment with nuget<div><pre>
<code class="yaml">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 "support@atlassianps.org"
- 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></code>
</pre></div>olivertag:help.appveyor.com,2012-11-13:Comment/455941172018-08-28T19:57:33Z2018-08-28T19:57:33ZUnderstanding deployment with nuget<div><p>Sorry I just realized that I missed this thread. We have <a href="https://www.appveyor.com/docs/packaging-artifacts/#artifacts-retention-policy">artifacts retention policy</a>, but Nuget packages are excluded from it, so they will persist.</p></div>Ilya Finkelshteyn