A compound of formula or a pharmaceutically acceptable salt thereof, wherein ring A is selected from 3-8 membered heterocycloalkyl, and the 3-8 membered heterocycloalkyl is optionally substituted with 1, 2 or 3 R; R 1, R 2, R 3, R 4 and R 5 are each independently selected from H, halogen, OH, NH 2, CN, C 1-6 alkyl and C 1-6 heteroalkyl, and the C 1-6 alkyl and C 1-6 heteroalkyl are optionally substituted with 1, 2 or 3 R; or R 1 and R 2 are connected together to form ring B; or R 2 and R 3 are connected together to form ring B; or R 3 and R 4 are connected together to form ring B; or R 4 and R 5 are connected together to form ring B; ring B is selected from phenyl, C 5-6 cycloalkenyl, 5-6 membered heterocycloalkenyl and 5-6 membered heteroaryl, and the phenyl, C 5-6 cycloalkenyl, 5-6 membered heterocycloalkenyl and 5-6 membered heteroaryl are optionally substituted with 1, 2 or 3 R a; R a is selected from halogen, OH, NH 2, CN, C 1-6 alkyl and C 1-6 heteroalkyl, and the C 1-6 alkyl and C 1-6 heteroalkyl are optionally substituted with 1, 2 or 3 R; R 6 is selected from H, halogen and C 1-6 alkyl, and the C 1-6 alkyl is optionally substituted with 1, 2 or 3 R; R 7 is selected from 4-6 membered heterocycloalkyl, 5-6 membered heteroaryl and C 5-6 cycloalkyl, and the 4-6 membered heterocycloalkyl, 5-6 membered heteroaryl and C 5-6 cycloalkyl are optionally substituted with 1, 2 or 3 R; L is selected from a single bond, -NH-, -S-, -O-, -C(=O)-, -C(=S)-, -CH 2 -, -CH(R b)- and -C(R b) 2 -; L' is selected from a single bond and -NH-; R b is selected from C 1-3 alkyl and C 1-3 heteroalkyl, and the C 1-3 alkyl and C 1-3 heteroalkyl are optionally substituted with 1, 2 or 3 R; R 8 is selected from H, C 1-6 alkyl and C 1-6 heteroalkyl, and the C 1-6 alkyl and C 1-6 heteroalkyl are optionally substituted with 1, 2 or 3 R; R is selected from halogen, OH, NH 2, CN, C 1-6 alkyl, C 1-6 heteroalkyl and C 3-6 membered cycloalkyl, and the C 1-6 alkyl, C 1-6 heteroalkyl and C 3-6 membered cycloalkyl are optionally substituted with 1, 2 or 3 R'; R' is selected from F, Cl, Br, I, OH, NH 2, CN, CH 3, CH 3 CH 2, CH 3 O, CF 3, CHF 2, CH 2 F, cyclopropyl, propyl, isopropyl, N(CH 3) 2 and NH(CH 3); "hetero" means a heteroatom or a heteroatomic group, the "hetero" in the 3-8 membered heterocycloalkyl, C 1-6 heteroalkyl, 5-6 membered heterocycloalkenyl, 5-6 membered heteroaryl, 4-6 membered heterocycloalkyl and C 1-3 heteroalkyl is each independently selected from -C(=O)N -, -N -, -NH-, N, -O-, -S-, -C(=O)O-, - C(=O)-, -C(=S)-, -S(=O)-, -S(=O) 2 - and -N C(=O)N -; in any of the cases above, the number of heteroatoms or heteroatomic groups is each independently selected from 1, 2 and 3. ring A is selected from 3-8 membered heterocycloalkyl, and the 3-8 membered heterocycloalkyl is optionally substituted with 1, 2 or 3 R; R 1, R 2, R 3, R 4 and R 5 are each independently selected from H, halogen, OH, NH 2, CN, C 1-6 alkyl and C 1-6 heteroalkyl, and the C 1-6 alkyl and C 1-6 heteroalkyl are optionally substituted with 1, 2 or 3 R; or R 1 and R 2 are connected together to form ring B; or R 2 and R 3 are connected together to form ring B; or R 3 and R 4 are connected together to form ring B; or R 4 and R 5 are connected together to form ring B; ring B is selected from phenyl, C 5-6 cycloalkenyl, 5-6 membered heterocycloalkenyl and 5-6 membered heteroaryl, and the phenyl, C 5-6 cycloalkenyl, 5-6 membered heterocycloalkenyl and 5-6 membered heteroaryl are optionally substituted with 1, 2 or 3 R a; R a is selected from halogen, OH, NH 2, CN, C 1-6 alkyl and C 1-6 heteroalkyl, and the C 1-6 alkyl and C 1-6 heteroalkyl are optionally substituted with 1, 2 or 3 R; R 6 is selected from H, halogen and C 1-6 alkyl, and the C 1-6 alkyl is optionally substituted with 1, 2 or 3 R; R 7 is selected from 4-6 membered heterocycloalkyl, 5-6 membered heteroaryl and C 5-6 cycloalkyl, and the 4-6 membered heterocycloalkyl, 5-6 membered heteroaryl and C 5-6 cycloalkyl are optionally substituted with 1, 2 or 3 R; L is selected from a single bond, -NH-, -S-, -O-, -C(=O)-, -C(=S)-, -CH 2 -, -CH(R b)- and -C(R b) 2 -; L' is selected from a single bond and -NH-; R b is selected from C 1-3 alkyl and C 1-3 heteroalkyl, and the C 1-3 alkyl and C 1-3 heteroalkyl are optionally substituted with 1, 2 or 3 R; R 8 is selected from H, C 1-6 alkyl and C 1-6 heteroalkyl, and the C 1-6 alkyl and C 1-6 heteroalkyl are optionally substituted with 1, 2 or 3 R; R is selected from halogen, OH, NH 2, CN, C 1-6 alkyl, C 1-6 heteroalkyl and C 3-6 membered cycloalkyl, and the C 1-6 alkyl, C 1-6 heteroalkyl and C 3-6 membered cycloalkyl are optionally substituted with 1, 2 or 3 R'; R' is selected from F, Cl, Br, I, OH, NH 2, CN, CH 3, CH 3 CH 2, CH 3 O, CF 3, CHF 2, CH 2 F, cyclopropyl, propyl, isopropyl, N(CH 3) 2 and NH(CH 3); "hetero" means a heteroatom or a heteroatomic group, the "hetero" in the 3-8 membered heterocycloalkyl, C 1-6 heteroalkyl, 5-6 membered heterocycloalkenyl, 5-6 membered heteroaryl, 4-6 membered heterocycloalkyl and C 1-3 heteroalkyl is each independently selected from -C(=O)N -, -N -, -NH-, N, -O-, -S-, -C(=O)O-, - C(=O)-, -C(=S)-, -S(=O)-, -S(=O) 2 - and -N C(=O)N -; in any of the cases above, the number of heteroatoms or heteroatomic groups is each independently selected from 1, 2 and 3.