ESRI has some pretty good documentation on this already; this is meant to be a simple summary explaining how our script tools get turned into geoprocessing widgets in our webmaps.
- Setup script as a python-based Script Tool in ArcMap
- Set the source to point to the script
- Set the parameters as specified in the script
- Run the Script Tool in ArcMap
- Share the (successful) results of the Script Tool with Share As -> Geoprocessing Service
- Publish or Overwrite a service (see note below for our workaround)
- Select a connection, folder, and service name
- Configure the options in the Service Editor according to the Script Tool's requirements; pay attention to input mode for each parameter
- Note the URL of your new Geoprocessing Service, or share it via AGOL
- In the AGOL Web AppBuilder, add a new Geoprocessing Widget
- Enter the URL of the GP Service, or select 'ArcGIS Online' and find your shared service.
- Verify the parameters came across correctly and set their default values.
- Change the icon, if desired.
For some reason, our particular setup causes the Share As -> Geoprocessing Service step to fail when we try to publish directly to a service or overwrite an existing service. To get around this, we choose "Save a service definition file" and then "No available connection." After setting everything up in the Service Editor, we manually upload the service definition via Server Tools -> Publishing -> Upload Service Definition in the Toolbox.
To update an existing GP Service, we first have to delete the existing service before uploading our new service definition.