构建最后提交的 SQL 脚本 VSTS [英] Build last commited SQL Script VSTS
问题描述
我是 VSTS 的新手,我想知道如何始终只构建最新提交的 SQL 脚本.
I'm new to VSTS and I want to know how to always build only the latest committed SQL Script.
示例:我从我的存储库中提交了 example.sql
,VSTS Build 只需要获取example.sql"zip 并发布工件以做好准备释放.
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.
我该怎么做?
推荐答案
VSTS 构建当前工作树的所有现有文件/脚本(repo 的指定分支).
VSTS build all the existing files/scripts of the current working tree (specified branch of the repo).
如果您想将最新更改的文件压缩并发布为工件,您可以添加PowerShell任务(对于linux和mac,您可以使用Shell脚本任务代替)作为助手.检测更改/添加的详细步骤如下:
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.使用 PowerShell 任务获取更改/添加的文件并将文件从 $(Build.SourcesDirectory)
复制到另一个目录(例如 $(Build.ArtifactStagingDirectory)files
).Powershell 脚本如下:
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.使用存档文件任务来压缩更改的文件. 例如从 $(Build.ArtifactStagingDirectory)files
目录到 $(Build.ArtifactStagingDirectory)pack$(Build.BuildId).zip
.
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.使用 Publish Build Artifacts 任务从 $(Build.ArtifactStagingDirectory)pack
目录发布压缩文件.
3. Use Publish Build Artifacts task to publish the zipped file from $(Build.ArtifactStagingDirectory)pack
directory.
这篇关于构建最后提交的 SQL 脚本 VSTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!