Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 87431bf

Browse files
edaenaEdaena Salinasmtarng
authored
Modify how pipelines are verified in the integration tests (#529)
* Verify pipeline with commit id * Use commit id to verify pipeline * Fix project values Co-authored-by: Edaena Salinas <[email protected]> Co-authored-by: Michael Tarng <[email protected]>
1 parent a40e151 commit 87431bf

File tree

2 files changed

+74
-10
lines changed

2 files changed

+74
-10
lines changed

tests/functions.sh

+49
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,55 @@ function verify_pipeline_with_poll () {
301301
fi
302302
}
303303

304+
function verify_pipeline_with_poll_and_source_version () {
305+
local pipeline_name=$3
306+
poll_timeout=$4
307+
poll_interval=$5
308+
source_version=$6
309+
end=$((SECONDS+$poll_timeout))
310+
loop_result="unknown"
311+
312+
echo "Attempting to verify that the pipeline build for $pipeline_name is successful..."
313+
pipeline_result=$(az pipelines build definition show --name $pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)
314+
pipeline_id=$(tr '"\""' '"\\"' <<< "$pipeline_result" | jq .id)
315+
echo "$pipeline_name has pipeline id of $pipeline_id"
316+
317+
build_run_exists=$(az pipelines build list --definition-ids $pipeline_id --org $AZDO_ORG_URL --p $AZDO_PROJECT | jq -r --arg source_version "$source_version" '.[].sourceVersion | select(. == $source_version) != null')
318+
319+
if [ "$build_run_exists" != "true" ]; then
320+
echo "Commit ID $source_version was not found in pipeline run $pipeline_name."
321+
exit 1
322+
fi
323+
324+
while [ $SECONDS -lt $end ]; do
325+
pipeline_builds=$(az pipelines build list --definition-ids $pipeline_id --org $1 --p $2)
326+
327+
# We use grep because of string matching issues
328+
echo "Get the build status for build..."
329+
pipeline_status=$(tr '"\""' '"\\"' <<< "$pipeline_builds" | jq .[0].status)
330+
echo "pipeline: $pipeline_name-$pipeline_id:"
331+
echo "pipeline_status this iteration --> $pipeline_status"
332+
if [ "$(echo $pipeline_status | grep 'completed')" != "" ]; then
333+
pipeline_result=$(tr '"\""' '"\\"' <<< "$pipeline_builds" | jq .[0].result)
334+
if [ "$(echo $pipeline_result | grep 'succeeded')" != "" ]; then
335+
echo "Successful build for pipeline: $pipeline_name-$pipeline_id!"
336+
loop_result=$pipeline_result
337+
break
338+
else
339+
echo "Expected successful build for pipeline: $pipeline_name-$pipeline_id but result is $pipeline_result"
340+
exit 1
341+
fi
342+
else
343+
echo "pipeline: $pipeline_name-$pipeline_id status is $pipeline_status. Sleeping for $poll_interval seconds"
344+
sleep $poll_interval
345+
fi
346+
done
347+
if [ "$loop_result" = "unknown" ]; then
348+
echo "Polling pipeline: $pipeline_name-$pipeline_id timed out after $poll_timeout seconds!"
349+
exit 1
350+
fi
351+
}
352+
304353
function validate_file () {
305354
echo "Validating file $1"
306355
if grep -q "$2" "$1";

tests/validations.sh

+25-10
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ spk hld install-manifest-pipeline --org-name $AZDO_ORG -d $AZDO_PROJECT --person
153153
# Will no longer be needed once install-manifest-pipeline supports adding a VG
154154
##################################
155155
cd $hld_dir
156+
hld_repo_commit_id=$(git log --format="%H" -n 1)
156157
spk hld append-variable-group $vg_name
157158
git add .
158159
git commit -m "Adding variable group $vg_name to pipeline"
@@ -163,7 +164,7 @@ echo "Successfully added variable group $vg_name to hld pipeline"
163164
pipeline_created=$(az pipelines show --name $hld_to_manifest_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)
164165

165166
# Verify hld to manifest pipeline run was successful
166-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 1
167+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 $hld_repo_commit_id
167168

168169
##################################
169170
# External Helm Chart Repo Setup START
@@ -275,7 +276,8 @@ spk project install-lifecycle-pipeline --org-name $AZDO_ORG --devops-project $AZ
275276
pipeline_created=$(az pipelines show --name $lifecycle_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)
276277

277278
# Verify lifecycle pipeline run was successful
278-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 180 15 1
279+
mono_repo_commit_id=$(git log --format="%H" -n 1)
280+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 180 15 $mono_repo_commit_id
279281

280282
# Approve pull request from lifecycle pipeline
281283
echo "Finding pull request that $lifecycle_pipeline_name pipeline created..."
@@ -297,7 +299,7 @@ spk service install-build-pipeline --org-name $AZDO_ORG -u $remote_repo_url -d $
297299
pipeline_created=$(az pipelines show --name $frontend_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)
298300

299301
# Verify frontend service pipeline run was successful
300-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 1
302+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 $mono_repo_commit_id
301303

302304
echo "Finding pull request that $frontend_pipeline_name pipeline created..."
303305
approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Updating $FrontEnd image tag to master"
@@ -360,11 +362,13 @@ pipeline1id=$(az pipelines build list --definition-ids $pipeline_id --organizati
360362
# App Mono Repo create ring
361363
##################################
362364
echo "Create ring in mono repo"
363-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 400 15 1
364365

365366
# Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
366367
echo "Wait for fabrikam-hld-to-fabrikam-manifests pipeline"
367-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 500 15 3
368+
cd $TEST_WORKSPACE/$hld_dir
369+
git pull
370+
hld_repo_commit_id=$(git log --format="%H" -n 1)
371+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 500 15 $hld_repo_commit_id
368372
ring_name=qa-ring
369373

370374
cd $TEST_WORKSPACE
@@ -379,12 +383,16 @@ git commit -m "Adding test ring"
379383
git push -u origin --all
380384

381385
# Wait for the lifecycle pipeline to finish and approve the pull request
382-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 300 15 2
386+
mono_repo_commit_id=$(git log --format="%H" -n 1)
387+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 300 15 $mono_repo_commit_id
383388
echo "Finding pull request that $lifecycle_pipeline_name pipeline created..."
384389
approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Reconciling HLD"
385390

386391
# Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
387-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 4
392+
cd $TEST_WORKSPACE/$hld_dir
393+
git pull
394+
hld_repo_commit_id=$(git log --format="%H" -n 1)
395+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 $hld_repo_commit_id
388396

389397
# Verify the file was added in the manifest repository
390398
cd $TEST_WORKSPACE
@@ -417,16 +425,20 @@ echo "Ring doc" >> ringDoc.md
417425
git add ringDoc.md
418426
git commit -m "Adding ring doc file"
419427
git push --set-upstream origin $ring_name
428+
mono_repo_commit_id=$(git log --format="%H" -n 1)
420429

421430
# Verify frontend service pipeline run was successful
422-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 3
431+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 $mono_repo_commit_id
423432
#complete merge
424433
echo "Finding pull request that $frontend_pipeline_name pipeline created..."
425434
approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Updating fabrikam.acme.frontend image tag to qa-ring"
426435

427436
# Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
428437
echo "Wait for hld to fabrikam manifests"
429-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 400 15 5
438+
cd $TEST_WORKSPACE/$hld_dir
439+
git pull
440+
hld_repo_commit_id=$(git log --format="%H" -n 1)
441+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 400 15 $hld_repo_commit_id
430442

431443
echo "Validating ring image tag in manifest repo"
432444
cd $TEST_WORKSPACE/$hld_dir
@@ -451,7 +463,10 @@ echo "Successfully reached the end of the service validations scripts."
451463

452464
# Verify hld to manifest pipeline run was successful, to verify the full end-end capture of
453465
# introspection data
454-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 5
466+
cd $TEST_WORKSPACE/$hld_dir
467+
git pull
468+
hld_repo_commit_id=$(git log --format="%H" -n 1)
469+
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 $hld_repo_commit_id
455470

456471
cd $TEST_WORKSPACE
457472
cd ..

0 commit comments

Comments
 (0)