The Jedi Code simply says:
There is no emotion, there is peace.
There is no ignorance, there is knowledge.
There is no passion, there is serenity.
There is no chaos, there is harmony.
There is no death, there is the Force.
The Jedi Code doesn't really say anything about whether or not Jedi should get involved in government and politics or take on a military role -- it's more focused on an individual and his connection to the Force.
Judging by the actions of the Jedi they obviously don't think involvement in politics and military action violates the Jedi Code because they have a long history of both. According to Obi-Wan the Jedi had served as peacekeepers of the Republic for many years:
For over a thousand generations the Jedi Knights were the guardians of peace and justice in the Old Republic.
Star Wars Episode IV: A New Hope (source)
Such a role meant the Jedi were involved in government and at least some level of politics, and such a role has a militaristic aspect to it as well. Furthermore, before the Jedi became peacekeepers of the Republic they had been forced to fight in an open war (the Jedi-Sith War), not unlike the fighting they participated in during the Clone Wars.
Mace Windu once made a comment that
...there aren't enough Jedi to protect the Republic. We are keepers of
the peace, not soldiers.
Star Wars Episode II: Attack of the Clones script
What did Mace Windu mean by this? I mean, in what other fashion would
the Jedi defend the Republic and keep peace, and not be so involved in
From the creation of the Republic at the end of the Jedi-Sith War until the Clone Wars the Sith were in hiding and no major conflicts arose -- the galaxy was largely at peace. The Republic did not have a standing military at this time (hence the controversy in Episode II over the Military Creation Act) but the Jedi were able to maintain the peace with the help of the Republic's Judicial Forces.
However, the long peace enjoyed by the Republic ended when discontent among the star systems of the Republic turned into the Separatist movement, which threatened to split the Republic in two:
After the Naboo Crisis and Palpatine’s election as Supreme Chancellor, many of Tarkin’s former Judicial peers would pin their hopes on Palpatine to keep the Republic from splintering. But the Separatist movement grew only stronger, and Tarkin and others were forced to accept that Palpatine, for all his talents, had come to power too late. Social injustices and trade inequities prompted hundreds of star systems to secede from the Republic, and local skirmishes became the norm. And then came war—a war that soon raged across the galaxy.
Tarkin, p. 93
Supreme Chancellor Palpatine refused to let the Separatists secede, thus bringing about the Clone Wars since both sides had armies with which to conduct open warfare (droids for the Separatists, clones for the Republic). In an attempt to serve as guardians of the Republic the Jedi were forced to fight in the Clone Wars as they had done in the Jedi-Sith War. Mace Windu's point was that the Jedi -- who had merely been acting as peacekeepers in a relatively peaceful galaxy -- were not equipped to fight a full-scale galactic war against vast droid armies.
Of course, Palpatine was actually behind the Separatist Crisis -- leading the Separatists as Darth Sidious. Palpatine was responsible for the Clone Wars, which was essentially a new Jedi-Sith War. But whereas the Jedi won the Jedi-Sith War, the Sith won the Clone Wars.
In Legends the history of the Jedi Order contains even more warfare than just the Jedi-Sith War. Clearly the Jedi do not think that the Jedi Code forbids military action in Legends, either.1
Legends also includes an alternate version of the Jedi Code which says:
Jedi are the guardians of peace in the galaxy.
Jedi use their powers to defend and protect, never to attack others.
Jedi respect all life, in any form.
Jedi serve others, rather than rule over them, for the good of the galaxy.
Jedi seek to improve themselves through knowledge and training.
The alternate version deals more with government, politics, and military roles than the main one. While it forbids Jedi from attacking it says that the Jedi should use their powers to "defend and protect" -- which could easily involve warfare.
1There is at least one notable instance in which the Jedi Council decided not to get involved in a war, at least initially: the Mandalorian Wars. However, the Jedi Council's decision not to get involved did not sit well with certain members of the Order, and those members split off to join the war on their own. In the end the Jedi were dragged into warfare anyway -- the Jedi Civil War.