Build last commited SQL Script VSTS

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 12:21:20

问题


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:


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.

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



来源:https://stackoverflow.com/questions/47476148/build-last-commited-sql-script-vsts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!