A cost-effective and highly reproducible capillary-based surface-enhanced Raman scattering (SERS) platform for sensitive, portable detection and identification of fentanyl is presented. Through encapsulating gold trisoctahedra (Au TOH) in the capillary tube for the first time, the SERS platform was constructed by combining the superior SERS properties of Au TOH and the advantages of capillaries in SERS signal amplification, facile sample extraction, and portable trace analysis. The effects of the size and density of Au TOH on the SERS performance were investigated by experiments and simulations, which showed that the maximum SERS enhancement was obtained for Au TOH with the size of 75 nm when particle density reached 74.54 counts/μm2. The proposed SERS platform possesses good reproducibility with a relative standard deviation (RSD) of less than 5%. As a demonstration, the platform was applied to detect fentanyl spiked in aqueous solution and serum samples with a limit of detection (LOD) as low as 1.86 and 40.63 ng/mL, respectively. We also validated the feasibility of the designed platform for accurate identification of trace fentanyl adulterated in heroin at mass concentration down to 0.1% (10 ng in 10 μg total). Overall, this work advances more explorations on capillary-based SERS platform to benefit portable trace analysis.