Thousands of union workers at a multibillion-dollar petrochemical plant being built outside Pittsburgh were given the choice of attending a speech by President Trump on Tuesday or staying away — and losing some of their pay for the week.

“Your attendance is not mandatory,” one of the construction site’s contractors wrote in rules for the speech that were shared with its employees, according to The Pittsburgh Post-Gazette, which first reported on the matter. But the rules said that only those who arrived at 7 a.m., had their work IDs scanned and then stood waiting for the president for several hours would get paid for the time.

“NO SCAN, NO PAY,” a supervisor for the contractor wrote, according to the paper.

The president’s appearance at the Royal Dutch Shell facility in Beaver County, where natural gas will be converted into plastic for a wide range of products, was publicized as a speech about energy, but it was hard to distinguish it from a standard campaign rally. Mr. Trump repeatedly targeted rivals and aired his political grievances.

At one point, Mr. Trump said he was going to speak to some of the union leaders representing the assembled workers about supporting his re-election. “And if they don’t,” Mr. Trump told the workers, “vote them the hell out of office, because they’re not doing their job.”