构建最后提交的SQL Script VSTS

问题描述 投票:1回答:1

我是VSTS的新手,我想知道如何始终只构建最新提交的SQL脚本。

示例:我从我的存储库中提交了example.sql,VSTS Build需要只获取“example.sql”压缩它并发布工件以准备发布。

我怎样才能做到这一点?

azure-devops azure-pipelines azure-pipelines-build-task
1个回答
2
投票

VSTS构建当前工作树的所有现有文件/脚本(repo的指定分支)。

如果要将最新更改的文件压缩并发布为工件,可以添加PowerShell任务(对于linux和mac,您可以使用Shell脚本任务)作为助手。详细步骤检测已更改/添加如下:

1.使用PowerShell任务获取已更改/添加的文件,并将文件从$(Build.SourcesDirectory)复制到另一个目录(例如$(Build.ArtifactStagingDirectory)\files)。 Powershell脚本如下:

$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

enter image description here

3.使用Publish Build Artifacts任务从$(Build.ArtifactStagingDirectory)\pack目录发布压缩文件。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.