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. Also, a solenoid when suspended freely, aligns itself in the north-south direction, thus behaving like a bar magnet. One end of the solenoid acts like a north pole and the other end the south pole.
The polarity of the solenoid AB can be changed by reversing the direction of the current. If we imagine that we are facing the coil end-on, then if the current flows in a clockwise direction, we are looking at the south pole. If the current flows in an anticlockwise direction, we are looking at the north pole. Hence, the polarity at A is north and polarity at B is south.
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. Like poles repel each other.
This is the fundamental principle of magnetism.