The polarity of the magnetic field (that is, which end is magnetic-north or magnetic-south) can easily be found from the Right hand thumb rule. If we hold the solenoid in our right hand, so that the fingers curl around it in the direction of the conventional current flow, then the thumb will point to the north pole of the magnet.
When magnetic compass with the north end is brought closer to the A end of the solenoid AB, the needle deflects towards the west, that is away from the solenoid because the magnetic compass that is pointing in the direction of the earth's magnetic field, i.e. north- south direction repels with the north pole of current carrying solenoid.