Mayor Thomas M. Menino is pledging to keep police officers who test dirty for cocaine off the force, even as a controversial state ruling ordering the city to rehire six cops who failed drug tests could open the floodgates to more rogue lawmen seeking their old jobs.

“If there’s anything I can do, they won’t get their jobs back,” Menino said. “That’s one of the conditions of employment: drug-free. We’ll appeal it to the highest courts.”

“It’s a bad decision,” the mayor added. “It has ramifications in other cases we might have in the city of Boston. It’s so unfortunate.”

The Herald reported yesterday that the state Civil Service Commission has ordered the reinstatement of six Boston cops who tested positive for cocaine in the early 2000s — with back pay to 2010.

In all, there have been at least 98 cops who have failed hair tests since 1999, and the ruling could open the door for them to also seek reinstatement, officials said.

The decision criticized the validity of hair sample drug tests, which have been an annual requirement for police officers since 1999. The fire department tests new employees’ hair upon hiring but after that conducts random urine and Breathalyzer tests.

“We’ve been using it for years and now all of a sudden there’s a question about it?” Menino said. “These individuals have proven with their tests that they’ve had some drug issues and they should not be on the department.”

The bill to reinstate the six — Richard Beckers, Ronnie Jones, Jacqueline McGowan, Shawn Harris, Walter Washington and George Downing — could eclipse $1.3 million if the ruling is allowed to stand, officials said. Each officer would reap about $225,000, officials estimate.

For Beckers, it was his second run-in with Boston Police Department brass. Hired in 1989, he received a 19-month suspension in 1995 for crashing a cruiser, records show. He was fired after his 2002 positive cocaine test.

In his testimony to the commission, Beckers blamed the positive tests on “contamination from unwashed instruments used by his barber,” “use of a hair straightening treatment” and “contamination during drug arrests.”

McGowan, meanwhile, was a two-time drug test flunky who was once disciplined for drinking on the job. She tested positive for cocaine in 1999 and was ordered into a 45-day rehabilitation program. She told the commission she was a cocaine addict in the late 1990s but was in recovery, records show.

The board rejected the appeals of four other cops fired after failing hair tests — Preston Thompson, Oscar Bridgeman, Rudy Guity and William Bridgeforth. Some of them made elaborate excuses for their positive tests, in­cluding Bridgeforth, who said he thought the powder he brushed off his cruiser seat was from doughnuts, not cocaine.

Officials from the Boston Police Patrolmen’s Association and the union’s attorney did not return messages. Guity declined to comment while attempts to reach all the officers were unsuccessful.

O’Ryan Johnson contributed to this report.