So you have to deal with a task that seems boring and dull and you keep pushing and pushing it till the very end of the milestone. In the end, you feel bad about your performance and you give in.
This is a typical occasion since we might have to deal with things that we don't consider cool and shiny from time to time throughout our careers. You know what? This is normal.
What is the solution? Break the task into small tangible steps so you make progress, ask for a pair programming session so you get some motivation from a teammate, and in general, don't let it take you down.
Procrastination is something that happens to all of us so you need to find ways to fight it.