Erik Kostson
Ansys Employee

One way is to run a thermal analysis with T1 and T2 on each end and couple that to a Static (this will transfer the temperatures over). The Static can then be as you said connected to a Buckling analysis.
Alternatively, and perhaps easier, in the Static add a Thermal Condition load, and then use tabular data with variable equal to your length coordinate (say Z if it is along length or any dimension you need).
All the best