I noticed something looking like a bug behavior publishing geoprocessing script tools (based on python script) as geoprocessing tasks on arcgis enterprise 10.5.
I created the tool and run it on ArcMap 10.5 successfully but when I try to publish the result it fails giving an error that informs me that the copy of the data on server is not allowed (it is correct, I disabled it on purpose).
All the data I use are in folders that are registered in the server data store, but I discovered that the problem is related to the arcpy.env.scratchGDB variable! If I use it, the server tries to upload intermediate data from the local path (that is not registered as data store) instead of working with the scratch gdb created in the service.
To make the geoprocessing tool published I need to substitute all the occurence of arcpy.env.scratchGDB with the path of a registered folder. Then, to make the tool work properly on server, I need to edit the python source in C:\arcgisserver\directories\arcgissystem\arcgisinput\MyTool.GPServer\extracted\v101\mytool\mytool.py and put in place the arcpy.env.scratchGDB variable
The same script worked perfectly on ArcGIS 10.3 (both Desktop and Server)