As most of the people wrote here before, of course it depends on the situation, but as there is no clear list of possible spots, I will try to make one.
1. Game / table dynamic. I saw some answers, that you should do it, if it is freeroll. In general, your play shouldn't be based on stakes that much. Even if you play NL2, you should still be thinking about ranges and correct play because it will make you win in the long run. While it is often true, that on
freerolls you will likely to get called all in, I played some freerolls, where people on my table seem to play quite tight. On some other, every hand was 2-3 all ins. So unless you want to go all in with first hand, just try to pay attention to what people are doing. People will act differently on regular and differently on hyper turbo etc.
2. Game type. If you are playing cash game and you go all in as not a result of 4-5 bet, you will mostly get called with premium
hands and the hands you wish to stay will fold. So I would advocate to never go all in on cash game. In tournaments it may be different because there are much more factors.
3. Stack size. This is probably the most important factor. In cash game you should always be at max buyin if possible, but on tournaments you will be often left with short stack. Whenever you go below ~10-15BB, you should be considering "shove or fold" mode, because with short stack size,
bluff equity goes down and you can't expect you will even get to the turn or the river.
4. Position and action. I am not sure if this was mentioned, but position here is also quite important. With premium hands, you have to guess what action will be the best to get money in. But also you need to be thinking about the isolation. AA may be the exception, but even with AA while you are at least 80% favourite to any other hand, it goes down ~10% with each player entering the pot. If you are on early position and short stacked, it is probably better to just go all in to isolate (with pocket pairs other than AA, you are not so happy if you only railse few BB and for instance you get 5 calls). But if you are on SB and it folds to you, most often going all in will get you only BB steal, which is probably not what you want with premium hands. This also relates to number of opponents in general. In some spots, especially heads up, depending on the type of the player, it may be the best play to limp-shove (especially when short stacked and your opponent raises you a lot).
There is no simple answer to that question, I think you always have to answer many specific questions to get the right answer. I would definitely not go with some fixed rules like "with xx it is always good to shove no matter what".