Build last commited SQL Script VSTS

2019-02-20 00:56发布

I'm new to VSTS and I want to know how to always build only the latest committed SQL Script.

Example: I committed example.sql from my repository, the VSTS Build needs to get only the "example.sql" zip it and publish the artifact to get ready to release.

How can I do that?

1条回答
别忘想泡老子
2楼-- · 2019-02-20 01:15

VSTS build all the existing files/scripts of the current working tree (specified branch of the repo).

If you want to zip and publish the latest changed files as artifacts, you can add a PowerShell task (for linux and mac, you can use Shell script task instead) for assistant. Detail steps to detect the changed/added as below:

1. Use PowerShell task to get changed/added file(s) and copy the file(s) from $(Build.SourcesDirectory) to another directory (such as $(Build.ArtifactStagingDirectory)\files). The Powershell script as below:

$files=$(git diff HEAD HEAD~ --name-only)
echo $files
$temp=$files -split ' '
$count=$temp.Length
echo "Total changed $count files"
New-Item -ItemType directory -Path $(Build.ArtifactStagingDirectory)\files
For ($i=0; $i -lt $temp.Length; $i++)
{
  $name=$temp[$i]
  echo "this is $name file"
  if (Test-Path "$(Build.SourcesDirectory)\$name")
    {
      Copy-Item $(Build.SourcesDirectory)\$name $(Build.ArtifactStagingDirectory)\files
    }
}

2. Use Archive files task to zip the changed files. Such as from $(Build.ArtifactStagingDirectory)\files directory to $(Build.ArtifactStagingDirectory)\pack\$(Build.BuildId).zip.

enter image description here

3. Use Publish Build Artifacts task to publish the zipped file from $(Build.ArtifactStagingDirectory)\pack directory.

enter image description here

查看更多
登录 后发表回答