0
votes

Problem: When my Azure DevOps build pipeline runs, I ONLY want to create a nuget package, if a solution's project's code has changed. if no changes, occured, i would love it if the pipeline could not continue in process (before the nuget push).

meaning - I do not want to release a new version of a nuget package if there were no code changes.

this is easy to do if i have an exclusive git repository for the project. because each git commit/push resembles a code change.. but i'm not sure how to do this if i have a .net solution with many projects inside (the nuget project being one of them).

2
Hi @Mike Rosol.Is there any update about this ticket? Feel free to let me know if the answers could give you some help. If the answesr could solve this issue, you may consider accepting one as answer. Thanks.Kevin Lu-MSFT

2 Answers

1
votes

I would like to share another method to achieve this goal.

In addition to adding a judgment on the file, you also need to add a judgment on the pipeline trigger method.

You can also try to use Git command and PowerShell Script to check the commit information.

Then you need to add Condition on the Nuget Push Task. (e.g. in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI')) This is Required.

You need to make sure that the Nuget Push task is triggered only when CI triggered. Otherwise, when you trigger the pipeline manually, this task will still create a new nuget version.

Here is an Example:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $files=$(git diff HEAD HEAD~ --name-only)
      $temp=$files -split ' '
      echo $temp
      $count=$temp.Length
      echo "Total changed $count files"
      For ($i=0; $i -lt $temp.Length; $i++)
      {
        $name=$temp[$i]
        echo "this is $name file"
        if ($name -like "filepath/test/*")
          {
            Write-Host "##vso[task.setvariable variable=IsContainFile]True"
          }
        else
          {
             Write-Host "##vso[task.setvariable variable=IsContainFile]False"
          }
      }
- task: NuGetCommand@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    ......
  condition: and(eq(variables['IsContainFile'], 'true'), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI'))

WorkFlow:

The Powershell task will check the file information. If the commits contains the target file or folder, it will set the variable value as true.

In Nuget Push task, When it meets two conditions(CI Trigger and Variable Value is true) at the same time, the task will run.

0
votes

If you have separate pipeline for creating nuget package you may consider path filer to trigger only then when there is a need to create a new nuget version:

# specific path build
trigger:
  branches:
    include:
    - master
    - releases/*
  paths:
    include:
    - docs/*
    exclude:
    - docs/README.md
``