Harrison Ford was not a janitor on the set of Star Wars — but he was a carpenter working between movie roles on the set.
Ford already had some 20 movie and TV credits (including guest starring roles in eight TV series) before he did Stars Wars.
However that wasn't enough to support his family on, so he turned to carpentry to supplement his income. Despite having no experience as a carpenter, he got a job building a recording studio for Sergio Mendes. Ford was recommended to other Hollywood types as “Carpenter to the Stars”, building a deck for Sally Kellerman and working as a stagehand for the rock group The Doors.
In 1972, Ford was hired to build cabinets at George Lucas' home. He was then picked by Lucas for a role in American Graffiti. The success of this film, which was written and directed by Lucas, helped finance his Star Wars film (which he also wrote and directed).
Ford, still working as a carpenter, was on the set of Stars Wars when Lucas recognized him from his role on American Graffiti. He was first asked to stand in for other actors auditioning for the parts. Later he was asked to read for the part of Han Solo himself. He was picked over stars such as Nick Nolte, Kurt Russell and Christopher Walken.
From his Reddit AMA:
I had helped George Lucas audition other actors for the principle [sic] parts, and with no expectation or indication that I might be considered for the part of Han, I was quite surprised when I was offered the part. My principle [sic] job at the time was carpentry, I had been under contract as an actor at Columbia and Universal.