The previously obtained solution of a nonstationary heat conduction problem for a two-piece rod, one end of which is in convective heat exchange with the environment, is generalized to the case of an inhomogeneous initial temperature field. The solution is presented as an eigenform expansion of the corresponding boundary problem and is expressed in terms of elementary functions. The obtained generalization makes it possible to propose an algorithm for solving a general problem with arbitrarily varying ambient temperature and heat exchange coefficient. The relations are presented, which allow to find axisymmetric stress fields in a two-layer cylinder by the calculated temperature field in a two-layer rod also in an analytical form. A comparative analysis has been made of the results obtained on the basis of the proposed analytical algorithm and the results of numerical calculations by the finite-element method. The aim of this comparison was to determine the influence of different simplifying assumptions used in constructing the algorithm on the accuracy of the results. These assumptions include: disregard of the cylinder curvature in the heat conductivity problem, disregard of the temperature dependence of material properties, change in the heat transfer coefficient. The comparison was performed using the example of a cylindrical body part under the thermal shock scenario. For these conditions, in general, the deviation of temperature and stresses calculated from the proposed approach from numerical results did not exceed 3%. In this case, the main part of the error -1.7% was introduced by a change in the dependence of physical properties on temperature. The second largest factor introduced into the calculation of the error was the failure to take into account the curvature of the cylinder when solving the problem of heat conduction. It corresponds to an error of about 1.1%. Considering that the thermoshock scenario is boundary in terms of temperature change rate, it can be stated that the obtained analytical solution is sufficient for practical assessment of the axisymmetric stressstrain state of the corresponding equipment and pipelines.