The bitter taste of cucumber comes from a chemical compound called cucurbitacin, produced by cucumbers and other members of this family of veggies, to ward away pests.
Since you can't tell if the cucumbers will turn bitter while they're growing, preventing plant stress is the only way to ensure that they don't turn bitter.
Stress to cucumber plants may be caused by under or overwatering, extreme temperatures, lack of nutrients and sunlight, low humidity or dry soil, and improper drainage.