Andrew Burton/Getty Image(WASHINGTON) — A federal judge says the Trump administration did not consider environmental consequences of the controversial Keystone XL pipeline, dealing a setback for the Trump administration and a win for environmental groups.

The judge put the pipeline on hold until the State Department conducts another review of the possible environmental impact of the project.

The Keystone XL pipeline would deliver crude oil from Canada and other parts of the U.S. to refineries in the Gulf Coast, covering more than 1,200 miles through Montana, South Dakota, and Nebraska.

The State Department initially denied the permit under the Obama administration citing the potential environmental impact, but shortly after President Donald Trump took office he revived the project and the administration reversed the previous denial and allowed the project to move forward.

But a federal judge in Montana ruled Thursday that the Trump administration’s reversal ignored information about the pipeline’s environmental impact to support reversing the Obama administration’s decision.

Judge Brian Morris cited a finding in a previous case that “an agency cannot simply disregard contrary or inconvenient factual determinations that it made in the past, anymore than it can ignore inconvenient facts when it writes on a blank slate.”

The judge put the pipeline on hold until the State Department fully evaluates the environmental impact, including the project’s impact on climate change, cultural resources, and potential for oil spills.

Environmental groups who oppose the pipeline and filed the lawsuit say the ruling is a victory for advocates and a significant setback for the pipeline.

President Donald Trump called the ruling “a disgrace” on Friday.

The company building the pipeline, TransCanada, said in a statement they are reviewing the ruling but they “remain committed to building this important energy infrastructure project.”