+# Query for a pre-existing gerrit review
+query_result=$(ssh -p 29418 "$GERRIT_USER@$GERRIT_HOST" gerrit query \
+ limit:1 owner:self is:open project:"$PROJECT" \
+ message: "$GERRIT_COMMIT_MESSAGE" \
+ topic: "$GERRIT_TOPIC")
+
+# Extract the change_id from the query_result
+job=$JOB_NAME/$BUILD_NUMBER
+# If available, add change_id to commit message
+if change_id=$(echo "$query_result" | grep 'Change-Id:' | awk '{print $2}'); then
+ echo "NOTE: Found gerrit review: $change_id"
+ message="Job: $job"$'\n'"Change-Id: $change_id"