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

Commit

Permalink
Modify how pipelines are verified in the integration tests (#529)
Browse files Browse the repository at this point in the history
* Verify pipeline with commit id

* Use commit id to verify pipeline

* Fix project values

Co-authored-by: Edaena Salinas <edaena@Edaenas-MBP.hsd1.ca.comcast.net>
Co-authored-by: Michael Tarng <20913254+mtarng@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 8, 2020
1 parent a40e151 commit 87431bf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 10 deletions.
49 changes: 49 additions & 0 deletions tests/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,55 @@ function verify_pipeline_with_poll () {
fi
}

function verify_pipeline_with_poll_and_source_version () {
local pipeline_name=$3
poll_timeout=$4
poll_interval=$5
source_version=$6
end=$((SECONDS+$poll_timeout))
loop_result="unknown"

echo "Attempting to verify that the pipeline build for $pipeline_name is successful..."
pipeline_result=$(az pipelines build definition show --name $pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)
pipeline_id=$(tr '"\""' '"\\"' <<< "$pipeline_result" | jq .id)
echo "$pipeline_name has pipeline id of $pipeline_id"

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')

if [ "$build_run_exists" != "true" ]; then
echo "Commit ID $source_version was not found in pipeline run $pipeline_name."
exit 1
fi

while [ $SECONDS -lt $end ]; do
pipeline_builds=$(az pipelines build list --definition-ids $pipeline_id --org $1 --p $2)

# We use grep because of string matching issues
echo "Get the build status for build..."
pipeline_status=$(tr '"\""' '"\\"' <<< "$pipeline_builds" | jq .[0].status)
echo "pipeline: $pipeline_name-$pipeline_id:"
echo "pipeline_status this iteration --> $pipeline_status"
if [ "$(echo $pipeline_status | grep 'completed')" != "" ]; then
pipeline_result=$(tr '"\""' '"\\"' <<< "$pipeline_builds" | jq .[0].result)
if [ "$(echo $pipeline_result | grep 'succeeded')" != "" ]; then
echo "Successful build for pipeline: $pipeline_name-$pipeline_id!"
loop_result=$pipeline_result
break
else
echo "Expected successful build for pipeline: $pipeline_name-$pipeline_id but result is $pipeline_result"
exit 1
fi
else
echo "pipeline: $pipeline_name-$pipeline_id status is $pipeline_status. Sleeping for $poll_interval seconds"
sleep $poll_interval
fi
done
if [ "$loop_result" = "unknown" ]; then
echo "Polling pipeline: $pipeline_name-$pipeline_id timed out after $poll_timeout seconds!"
exit 1
fi
}

function validate_file () {
echo "Validating file $1"
if grep -q "$2" "$1";
Expand Down
35 changes: 25 additions & 10 deletions tests/validations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ spk hld install-manifest-pipeline --org-name $AZDO_ORG -d $AZDO_PROJECT --person
# Will no longer be needed once install-manifest-pipeline supports adding a VG
##################################
cd $hld_dir
hld_repo_commit_id=$(git log --format="%H" -n 1)
spk hld append-variable-group $vg_name
git add .
git commit -m "Adding variable group $vg_name to pipeline"
Expand All @@ -163,7 +164,7 @@ echo "Successfully added variable group $vg_name to hld pipeline"
pipeline_created=$(az pipelines show --name $hld_to_manifest_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT)

# Verify hld to manifest pipeline run was successful
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 1
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 $hld_repo_commit_id

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

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

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

# Verify frontend service pipeline run was successful
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 1
verify_pipeline_with_poll_and_source_version $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 $mono_repo_commit_id

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

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

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

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

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

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

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

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

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

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

cd $TEST_WORKSPACE
cd ..
Expand Down

0 comments on commit 87431bf

Please sign in to comment.