Skip to content

Commit 03d59f0

Browse files
authored
ci simplification - fixes fetchdepth issue (#78)
* can I check this in? * but does this fix it? * using the right job name is important when trying to use output variables * are resources.repositories.tSQLtArtifacts variables available? * what env vars do I have again? * github uri is not available in the env * git magic * do not need to list env vars * why do we appear to have more branches than expected for depth=1 * Update AZ_MainPipeline.yml Specify full path of validate build 🐜 file * tsqlt is the right path * attempt to simplify paths * goodbye sql server 2008R2E * fewer git shenanigans * NO --> D:\a\1+\tSQLt\Build\output\TestResults\ * concatenating strings is hard * It is too much trouble and probably not a great pattern to get rid of $basePath * fixed spelling error
1 parent f9b9e18 commit 03d59f0

File tree

1 file changed

+80
-47
lines changed

1 file changed

+80
-47
lines changed

CI/AZ_MainPipeline.yml

Lines changed: 80 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ resources:
1717
type: github
1818
name: tSQLt/tmp6
1919
endpoint: GitHub-tSQLt-Robot
20-
ref: (https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops) -- {{ $ArtifactBranchName }}
2120

2221

2322
stages:
@@ -33,9 +32,43 @@ stages:
3332
persistCredentials: true
3433
path: tSQLtArtifacts
3534

35+
- task: PowerShell@2
36+
name: list_remote_branch
37+
inputs:
38+
targetType: 'inline'
39+
failOnStderr: false
40+
script: |
41+
$CheckIfGitOk = {param($isOk);if(-not $isOk){Write-Host "##vso[task.logissue type=error]GIT Failed!";throw "git failed!"}};
42+
43+
Set-Location "$(Pipeline.Workspace)\tSQLtArtifacts\";
44+
45+
Write-Host ("ArtifactBranchName: {0}" -f "$(ArtifactBranchName)");
46+
try{
47+
48+
$remoteURL = git config remote.origin.url
49+
$CheckIfGitOk.invoke($?);
50+
51+
$branch = (git ls-remote --heads $remoteURL $(ArtifactBranchName))
52+
$CheckIfGitOk.invoke($?);
53+
54+
if( -not [string]::IsNullOrEmpty($branch) )
55+
{
56+
Write-Host "##vso[task.setvariable variable=BuiltAlready;isOutput=true]true";
57+
Write-Host "Build Branch Found";
58+
}
59+
else
60+
{
61+
Write-Host "##vso[task.setvariable variable=BuiltAlready;isOutput=true]false";
62+
Write-Host "Build Branch NOT Found";
63+
};
64+
}catch{
65+
throw "git failed. See prior errors.";
66+
}
67+
git status
68+
3669
- job: CompileCLR
3770
dependsOn: Check_If_Built_Already
38-
condition: failed()
71+
condition: and(succeeded(),eq(dependencies.Check_If_Built_Already.outputs['list_remote_branch.BuiltAlready'], 'false'))
3972
timeoutInMinutes: 10
4073
cancelTimeoutInMinutes: 2
4174

@@ -125,12 +158,12 @@ stages:
125158
targetType: 'inline'
126159
failOnStderr: true
127160
script: |
128-
$BasePath = "$(Build.SourcesDirectory)\Build\output\";
129-
$ArtifactPath = ($BasePath+"Artifact\");
130-
New-Item -Path $ArtifactPath -ItemType directory -Force
131-
$ArtifactFiles = (@("Version.txt","tSQLt.zip","tSQLt.tests.zip")|%{$BasePath+$_});
132-
$ArtifactFiles|Copy-Item -Verbose -Destination $ArtifactPath;
133-
Set-Content -Path ($ArtifactPath+"CommitId.txt") -Value "$(Build.SourceVersion)"
161+
$basePath = "$(Build.SourcesDirectory)\Build\output\";
162+
$artifactPath = ($basePath+"Artifact\");
163+
New-Item -Path $artifactPath -ItemType directory -Force
164+
$ArtifactFiles = (@("Version.txt","tSQLt.zip","tSQLt.tests.zip")|%{$basePath+$_});
165+
$ArtifactFiles|Copy-Item -Verbose -Destination $artifactPath;
166+
Set-Content -Path ($artifactPath+"CommitId.txt") -Value "$(Build.SourceVersion)"
134167
135168
- task: PublishPipelineArtifact@1
136169
inputs:
@@ -148,6 +181,7 @@ stages:
148181
- checkout: tSQLtArtifacts
149182
clean: true
150183
lfs: false
184+
fetchDepth: 1
151185
persistCredentials: true
152186
path: tSQLtArtifacts
153187

@@ -158,6 +192,11 @@ stages:
158192
artifactName: 'tSQLtAndTests'
159193
targetPath: '$(Pipeline.Workspace)\tmp'
160194

195+
- task: AzureKeyVault@1
196+
inputs:
197+
azureSubscription: 'tSQLt CI Subscription(58c04a99-5b92-410c-9e41-10262f68ca80)'
198+
KeyVaultName: 'tSQLtSigningKey'
199+
161200
- task: PowerShell@2
162201
name: StoreInArtifactRepo
163202
env:
@@ -170,7 +209,6 @@ stages:
170209
script: |
171210
$CheckIfGitOk = {param($isOk);if(-not $isOk){Write-Host "##vso[task.logissue type=error]GIT Failed!";throw "GIT Failed!"}};
172211
173-
Get-Location;
174212
Set-Location "$(Pipeline.Workspace)\tSQLtArtifacts\";
175213
Write-Host ("ArtifactBranchName: {0}" -f "$(ArtifactBranchName)");
176214
try{
@@ -179,6 +217,12 @@ stages:
179217
git status
180218
git remote show origin
181219
220+
Write-Host "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ";
221+
Write-Host "";
222+
git branch --remotes
223+
Write-Host "";
224+
Write-Host "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ";
225+
182226
git switch -c "$(ArtifactBranchName)"
183227
$CheckIfGitOk.invoke($?);
184228
@@ -217,7 +261,6 @@ stages:
217261
strategy:
218262
matrix: {
219263
'2008R2':{'SQLVersionEdition':'2008R2Std'},
220-
'2008R2E':{'SQLVersionEdition':'2008R2Ent'},
221264
'2012':{'SQLVersionEdition':'2012Ent'},
222265
'2014':{'SQLVersionEdition':'2014'},
223266
'2016':{'SQLVersionEdition':'2016'},
@@ -242,6 +285,7 @@ stages:
242285
- checkout: tSQLtArtifacts
243286
clean: true
244287
lfs: false
288+
fetchDepth: 1
245289
persistCredentials: true
246290
path: tSQLtArtifacts
247291

@@ -250,27 +294,22 @@ stages:
250294
inputs:
251295
targetType: 'inline'
252296
script: |
253-
$ArtifactTargetPath= '$(Pipeline.Workspace)/tSQLt/Build_Artifact'
254297
$CheckIfGitOk = {param($isOk);if(-not $isOk){Write-Host "##vso[task.logissue type=error]GIT Failed!";throw "GIT Failed!"}};
255298
256-
Set-Location "$(Pipeline.Workspace)\tSQLtArtifacts\";
257-
258-
# Write-Host ("ArtifactBranchName: {0}" -f "$(ArtifactBranchName)");
259-
# try{
260-
# git status
261-
# git remote show origin
262-
263-
# git fetch
264-
# git checkout "$(ArtifactBranchName)"
265-
# $CheckIfGitOk.invoke($?);
299+
Set-Location "$(Pipeline.Workspace)/tSQLtArtifacts";
300+
$ArtifactTargetPath= '$(Pipeline.Workspace)/tSQLt/Build_Artifact'
301+
Write-Host ("ArtifactBranchName: {0}" -f "$(ArtifactBranchName)");
266302
267-
# git status
268-
# }catch{
269-
# throw "Git Failed. See prior errors.";
270-
# }
303+
try{
304+
git fetch origin $(ArtifactBranchName):$(ArtifactBranchName)
305+
$CheckIfGitOk.invoke($?);
306+
git checkout $(ArtifactBranchName)
307+
$CheckIfGitOk.invoke($?);
308+
}catch{
309+
throw "git failed. See prior errors.";
310+
}
271311
272312
New-Item -Path $ArtifactTargetPath -ItemType directory -Force
273-
274313
Copy-Item -Path "*" -Verbose -Destination $ArtifactTargetPath
275314
276315
- task: AzurePowerShell@4
@@ -288,12 +327,7 @@ stages:
288327
azurePowerShellVersion: 'LatestVersion'
289328
ScriptType: 'InlineScript'
290329
Inline: |
291-
Write-Host '$(Build.Repository.LocalPath)';
292-
(Get-ChildItem);
293-
Set-Location $(Build.Repository.LocalPath)/..
294-
(Get-ChildItem);
295-
Set-Location $(Build.Repository.LocalPath)/../tSQLt
296-
(Get-ChildItem);
330+
Set-Location $(Pipeline.Workspace)/tSQLt
297331
.("CI/CommonFunctionsAndMethods.ps1")
298332
299333
$SqlPort = Get-Random -minimum $env:SQLPORTMINIMUM -maximum $env:SQLPORTMAXIMUM
@@ -363,11 +397,11 @@ stages:
363397
- task: Ant@1
364398
name: Run_tSQLt_validatebuild_xml
365399
inputs:
366-
buildFile: '../tSQLt/Build/tSQLt.validatebuild.xml'
400+
buildFile: '$(Pipeline.Workspace)/tSQLt/Build/tSQLt.validatebuild.xml'
367401
options: '-Ddb.version="$(SQLVersion)" -Ddb.server="$(FQDNAndPort)" -Ddb.name=tSQLt_dev -Ddb.login="-U $(tSQLt-UserForCIEnvironment-UserName) -P $(tSQLt-UserForCIEnvironment-Password)" -Dsqlcmd.path="$(SQLCMDPath)"'
368402
targets: 'all'
369403
publishJUnitResults: true
370-
testResultsFiles: '../**/?(Example)TestResults*.xml'
404+
testResultsFiles: '$(Pipeline.Workspace)/tSQLt/**/?(Example)TestResults*.xml'
371405
testRunTitle: '$(SQLVersionEdition)'
372406
javaHomeOption: 'JDKVersion'
373407

@@ -378,26 +412,25 @@ stages:
378412
failOnStderr: true
379413
script: |
380414
"---------------------------------------------------"
381-
$BasePath = "$(Build.SourcesDirectory)\..";
382-
$BasePath;
415+
$basePath = "$(Pipeline.Workspace)";
416+
$basePath;
383417
"==================================================="
384-
$ArtifactPath = ($BasePath+"\tSQLt\Build\output\TestResults\");
385-
$ArtifactPath;
418+
$artifactPath = "$basePath\tSQLt\Build\output\TestResults\";
419+
$artifactPath;
386420
"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
387-
New-Item -Path $ArtifactPath -ItemType directory -Force
388-
(Get-ChildItem $BasePath -recurse);
421+
New-Item -Path $artifactPath -ItemType directory -Force
389422
"== == == == == == == == == == == == == == == == == "
390-
(Get-ChildItem $BasePath -recurse)|Out-File -FilePath $ArtifactPath+"dir.txt"
391-
(Get-ChildItem $BasePath -recurse -include "*TestResults*.xml").FullName;
423+
(Get-ChildItem $basePath -recurse)|Out-File -FilePath $artifactPath+"dir.txt"
424+
(Get-ChildItem $basePath -recurse -include "*TestResults*.xml").FullName;
392425
"==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-"
393-
(Get-ChildItem $BasePath -recurse -include "*TestResults*.xml").FullName|Copy-Item -Destination $ArtifactPath -recurse -PassThru
394-
Set-Content -Path ($ArtifactPath+"CommitId.txt") -Value "$(Build.SourceVersion)"
426+
(Get-ChildItem $basePath -recurse -include "*TestResults*.xml").FullName|Copy-Item -Destination $artifactPath -recurse -PassThru
427+
Set-Content -Path ($artifactPath+"CommitId.txt") -Value "$(Build.SourceVersion)"
395428
"=== === === === === === === === === === === === ==="
396429
397430
- task: PublishPipelineArtifact@1
398431
name: PublishTestResultArtifact
399432
inputs:
400-
targetPath: '$(Build.SourcesDirectory)/../tSQLt/Build/output/TestResults'
433+
targetPath: '$(Pipeline.Workspace)/tSQLt/Build/output/TestResults'
401434
artifact: 'TestResults_$(SQLVersionEdition)'
402435
publishLocation: 'pipeline'
403436

@@ -409,7 +442,7 @@ stages:
409442
inputs:
410443
targetType: 'inline'
411444
script: |
412-
$CheckIfGitOk = {param($isOk);if(-not $isOk){Write-Host "##vso[task.logissue type=error]GIT Failed!";throw "GIT Failed!"}};
445+
$CheckIfGitOk = {param($isOk);if(-not $isOk){Write-Host "##vso[task.logissue type=error]git failed!";throw "git failed!"}};
413446
414447
$TagName = "$(SQLVersionEdition)_$(Build.BuildId)"
415448
@@ -431,7 +464,7 @@ stages:
431464
432465
git status
433466
}catch{
434-
throw "Git Failed. See prior errors.";
467+
throw "git failed. See prior errors.";
435468
}
436469
437470
##--##--##--##--##--##--##--##--##--##---##--##--##--##--##--##--##--##--##--##

0 commit comments

Comments
 (0)