Appveyor pushed a nuget package which don't match the tag while APPVEYOR_REPO_TAG: true in appveyor.yml.

moh.hassan20's Avatar

moh.hassan20

02 Jan, 2020 11:56 PM

I publish the package to nuget from appveyor when I push a tag to the Repo and appveyor.yml contain:

version: 2.7.{build}

.
- provider: NuGet
  api_key:
    secure: ....
  artifact: 'NuGetPackages'
  on:
    APPVEYOR_REPO_TAG: true

I, pushed a tag v2.7.0 to the github Repo, and Appveyor, for unknown reason for me, published two packages to nuget feed:
v2.7.0 (which is OK and match the tag)
and another package v2.7.82(which don't match the tag I pushed and it is not needed).

Why Appveyor push package 1.7.82 while it's not matched with tag (APPVEYOR_REPO_TAG: true)?
What script can I add to appveyor.yml to avoid generating a package which does not match the tag I push ?
The file appveyor.yml is attached.

  1. Support Staff 1 Posted by Feodor Fitsner on 03 Jan, 2020 07:01 PM

    Feodor Fitsner's Avatar

    Could you please give a link to that build please?

  2. 2 Posted by moh.hassan20 on 03 Jan, 2020 08:03 PM

    moh.hassan20's Avatar

    Hi Feodor,
    The two builds are:
    v2.7.82:
    https://ci.appveyor.com/project/commandlineparser/commandline/builds/29843949
    Appveyor publish only one package.

    v2.7.0: https://ci.appveyor.com/project/commandlineparser/commandline/builds/29843873

    <https://ci.appveyor.com/project/commandlineparser/commandline/builds/29843873>
    Appveyor publish two packages successfully

    It's supposed that build publish two packages, and you find in every build
    different error messages:
    >Error updating GitHub release: Not Found
    >Exception calling "UpdateBuildDetails" with "10" argument(s): "Build with
    specified version already exists."At C:\Program
    Files\AppVeyor\BuildAgent\Modules\build-worker-api\build-worker-api.psm1:41
    char:5

    My concern is version 2.7.82 has not a corresponding tag (i.e no tag named
    2.7.82).

    I want your advice how to avoid such a problem in the build
       i.e unique tag for publishing packages
           the version of the package should match the tag
    Also, how to insure that either the two packages published together or fail
    together.

    Thanks for help and support.

    // Please reply above this line
    ==================================================

    *From*: Feodor Fitsner (Support staff)

    Could you please give a link to that build please?

    On Thu, Jan 02 at 03:56 PM PST, moh.hassan20 wrote:

    I publish the package to nuget from appveyor when I push a tag to the Repo
    and appveyor.yml contain:

    version: 2.7.{build}
    .
    - provider: NuGet
      api_key:
        secure: ....
      artifact: 'NuGetPackages'
      on:
        APPVEYOR_REPO_TAG: true

    I, pushed a tag v2.7.0 to the github Repo, and Appveyor, for unknown reason
    for me, published two packages to nuget feed:
    v2.7.0 (which is OK and match the tag)
    and another package v2.7.82(which don't match the tag I pushed and it is
    not needed).

    Why Appveyor push package 1.7.82 while it's not matched with tag
    (APPVEYOR_REPO_TAG: true)?
    What script can I add to appveyor.yml to avoid generating a package which
    does not match the tag I push ?
    The file appveyor.yml is attached.

  3. Support Staff 3 Posted by Feodor Fitsner on 03 Jan, 2020 11:26 PM

    Feodor Fitsner's Avatar

    You don't need changing AppVeyor build version on tags, just let it increment naturally. However, while packaging NuGet packages you use --version-suffix %APPVEYOR_BUILD_VERSION% where APPVEYOR_BUILD_VERSION is the system variable.

    You can introduce your own variable for packaging version, for example: PACKAGE_VERSION and then define it as:

    init:
      - ps: |
          git config --global core.autocrlf input
          
          if ($env:APPVEYOR_REPO_TAG -eq "true") {
            $ver = $env:APPVEYOR_REPO_TAG_NAME
            if($ver.StartsWith("v") -eq $true) { $ver = $ver.Substring(1) }
            $env:PACKAGE_VERSION = $ver
          } else {
            $env:PACKAGE_VERSION = $env:APPVEYOR_BUILD_VERSION
          }
    

    then use %PACKAGE_VERSION% instead.

  4. 4 Posted by moh.hassan20 on 14 Jan, 2020 11:45 PM

    moh.hassan20's Avatar

    Thanks @ Feodor for reply and sorry for delay responding.

    Do you mean change appveyor.yml as:

    build_script:
    - cmd: dotnet build src/CommandLine/ -c Release --version-suffix %PACKAGE_VERSION% /p:BuildTarget=%BUILD_TARGET%
    
    after_test:
    - cmd: dotnet pack src/CommandLine/ -c Release --version-suffix %PACKAGE_VERSION% /p:BuildTarget=%BUILD_TARGET%
    

    Kindly, can you explain how this change help in avoiding generating package when APPVEYOR_REPO_TAG:false.

  5. Support Staff 5 Posted by Feodor Fitsner on 15 Jan, 2020 12:39 AM

    Feodor Fitsner's Avatar

    To build/package on tag you can add a simple check like:

    build_script:
    - cmd: if "%APPVEYOR_REPO_TAG%" == "true" dotnet build src/CommandLine/ -c Release --version-suffix %PACKAGE_VERSION% /p:BuildTarget=%BUILD_TARGET%
    
    after_test:
    - cmd: if "%APPVEYOR_REPO_TAG%" == "true" dotnet pack src/CommandLine/ -c Release --version-suffix %PACKAGE_VERSION% /p:BuildTarget=%BUILD_TARGET%
    
  6. 6 Posted by moh.hassan20 on 15 Jan, 2020 02:05 AM

    moh.hassan20's Avatar

    I think in this case I can't build or test when "%APPVEYOR_REPO_TAG%" == "false"
    But, I need to build /test without pushing a package.

  7. Support Staff 7 Posted by Feodor Fitsner on 15 Jan, 2020 02:07 AM

    Feodor Fitsner's Avatar

    Then your yaml attached to the original posting has APPVEYOR_REPO_TAG: true already on both deployments. Or what do you mean?

  8. 8 Posted by moh.hassan20 on 15 Jan, 2020 02:18 AM

    moh.hassan20's Avatar

    I mean:
    when APPVEYOR_REPO_TAG: false build and test
    when APPVEYOR_REPO_TAG: true build , test and push when success

    Currently, that is what I do.
    Only i want to protect pushing package that don't match the tag (as what happen in this issue).

  9. Support Staff 9 Posted by Feodor Fitsner on 16 Jan, 2020 05:09 AM

    Feodor Fitsner's Avatar

    Then you could introduce another variable which would be "AND" between APPVEYOR_REPO_TAG == true and "package match the tag" conditions. Then use that variable in deploy conditions.

  10. 10 Posted by moh.hassan20 on 16 Jan, 2020 06:49 AM

    moh.hassan20's Avatar

    +1

    Thanks @Feodor for your suggestion.

    Based on your solution, I can add the next code to yml

    init:
    ....
    
      - ps: |
          $env:PUSH_OK =false      
          if ($env:APPVEYOR_REPO_TAG_NAME -eq $env:PACKAGE_VERSION) 
             $env:PUSH_OK =true
     ....        
    
    
    - provider: NuGet
      api_key:
        secure: .....Ab4T...
      artifact: 'NuGetPackages'
      on:
        APPVEYOR_REPO_TAG: true
        PUSH_OK: true
    

    Is it right?

  11. Support Staff 11 Posted by Feodor Fitsner on 16 Jan, 2020 06:58 AM

    Feodor Fitsner's Avatar

    Yep, looks good to me. Give it a try.

  12. 12 Posted by moh.hassan20 on 16 Jan, 2020 07:27 AM

    moh.hassan20's Avatar

    I'll give it a try and feedback
    Many thanks for help and support.

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • appveyor.yml 1.56 KB

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