I have connected two Juniper routers with a QSFP28 optics and I need to find out the length of the optical cable I have used. Is there a command to check that in the router?
No, you can find out with optical test equipment such as an OTDR, but not with the less-sophisticated telemetry available in a router/switch.
You can know the path loss (limited by the accuracy of the optics' Tx/Rx power meters) but that loss includes things like bends, dirt, connectors, etc. so it's not usable as a good estimate of distance.