Magento\Customer\Model\Session $customerSession using this class you will get the current customer group id
protected $_customerSession;
public function __construct(
\Magento\Customer\Model\Session $customerSession,
) {
$this->_customerSession = $customerSession;
}
public function getGroupId(){
if($this->_customerSession->isLoggedIn()):
echo $customerGroup=$this->_customerSession->getCustomer()->getGroupId();
endif;
}
NOTE: You only get customer id if the customer logged in