0

In azure devops I have a pipeline that deploys artifacts from one synapse environment to another (dev to prod) using Synapse workspace deployment@2 task and it works fine but its starting to take a long time for it to complete and i wanted to find a way for the pipeline to Validate and Deploy only the changed artifacts.

I tried to get the changed files with "git diff" and insert it into a temp directory and then use that as my source directory but that didnt work, but if it did i still can't figure how to make Synapse workspace deployment task take only that changed files.

1 Answer 1

1

Your idea that using the 'git diff' command to filter the changed files should be okay.

You can try to configure your pipeline with the following steps:

  1. Add a script/PowerShell/Bash task before the Synapse workspace deployment@2 task to do the things below.

    • Call the REST API "Builds - Get Build Changes" to get all the commits associated with current pipeline run.
    • Use the 'git diff' command to list all the changed files from the commits.
    • Copy the changed files into another directory.
  2. On the Synapse workspace deployment@2 task, you can set the configurations below.

    • Select validateDeploy as the value of operation (Operation Type) option.
    • Pass the path of the directory as the value of the ArtifactsFolder (Artifacts root folder) option.
    • Ensure the option DeleteArtifactsNotInTemplate (Delete Artifacts Not In Template) is false.

See below sample as reference.

variables:
  armConnection: myArmConnection
  resourceGroup: myResourceGroup
  synapseWorkspace: myWorkspace

steps:
- task: PowerShell@2
  displayName: 'Pick changed files'
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  inputs:
    pwsh: true
    targetType: inline
    script: |
      Write-Host "Getting modified files..."
      $prefix_url = "$(System.CollectionUri)"
      $project = "$(System.TeamProject)"
      $buildId = $(Build.BuildId)
      $url = "${prefix_url}${project}/_apis/build/builds/${buildId}/changes?includeSourceChange=true&api-version=7.0"
      $headers = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
      $response=Invoke-RestMethod -Uri $url -Headers $headers
      $changesCount = $response.count

      $modifiedFiles= git diff HEAD HEAD~$changesCount --name-only

      Write-Host "Copying modified files..."
      $srcDir = "$(Build.SourcesDirectory)"
      $destDir = "$(Build.ArtifactStagingDirectory)"

      foreach ($file in $modifiedFiles)
      {
        Write-Host "Copying file: $srcFile ---> $destFile"
        $srcFile = "$srcDir/$file"
        $destFile = "$destDir/$file"

        $parentDir = Split-Path -Parent $destFile
        if (-not (Test-Path $parentDir))
        {
          New-Item -Path $parentDir -ItemType Directory
        }

        Copy-Item "$srcFile" -Destination "$destFile"
      }

- task: Synapse workspace deployment@2
  inputs:
    operation: 'validateDeploy'
    ArtifactsFolder: '$(Build.ArtifactStagingDirectory)'
    azureSubscription: $(armConnection)
    ResourceGroupName: $(resourceGroup)
    TargetWorkspaceName: $(synapseWorkspace)
    DeleteArtifactsNotInTemplate: false

Sign up to request clarification or add additional context in comments.

1 Comment

How do you overwrite prods link service parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.