I need to publish my python script as a geoprocessing service, which I've never done before. The geoprocessing service needs to take as input the SSRS Url, extract the SGID value, generate a jpeg of the map linked to the SGID (Cadastre ID) and return the output jpeg path as an url that the SSRS can use to access the jpeg to insert it into the report template.
We currently have the following CMV viewer (V&V Mapper) that we are using. Our SQL Dev has written a SQL SSRS report that is triggered when the following link (Tablemap) below is selected.

TableMap: MoreInfo

SSRS URL: "http://197.85.5.236:8080/ReportServer/Pages/ReportViewer.aspx?%2fVnV_BO%2fLanduseSummary&SGID=929102&rs:Format=PDF"
I've attached my python script below that as an input argument accepts the SSRS Url and extracts the SGID value using Python Urlparse module (i.e. I'm still using Python 2.7.8 and ArcGIS 10.3.1).
<SPAN class="string token">'''
Created on 12 Sep 2016
Generate a JPEG
for a Land Parcel
indicating the irrigation
status based on SGID
@author: PeterW
'''</SPAN>
<SPAN class="comment token"># import site-packages and modules</SPAN>
<SPAN class="keyword token">import</SPAN> urlparse
<SPAN class="keyword token">import</SPAN> math
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># set environment settings</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token"># set arguments</SPAN>
<SPAN class="comment token"># example of incomming url from ssrs request:</SPAN>
<SPAN class="comment token"><SPAN># </SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2F197.85.5.236%3A8080%2FReportServer%2FPages%2FReportViewer.aspx%3F%252fVnV_BO%252fLanduseSummary%26SGID%3D930016%26rs%3AFormat%3DPDF" target="_blank">http://197.85.5.236:8080/ReportServer/Pages/ReportViewer.aspx?%2fVnV_BO%2fLanduseSummary&SGID=930016&rs:Format=PDF</A></SPAN>
input_sgid <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># fixed input mcd and output jpeg folder</SPAN>
input_mxd <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\Python2\VandV\mxd\VandV_Letter_Maps_160928.mxd"</SPAN>
output_folder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"Z:\Peter.Wilson\test"</SPAN>
<SPAN class="comment token"># function to extract sgid from sql ssrs url</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">extract_sgid</SPAN><SPAN class="punctuation token">(</SPAN>input_sgid<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
sgid <SPAN class="operator token">=</SPAN> urlparse<SPAN class="punctuation token">.</SPAN>parse_qsl<SPAN class="punctuation token">(</SPAN>urlparse<SPAN class="punctuation token">.</SPAN>urlparse<SPAN class="punctuation token">(</SPAN>input_sgid<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>query<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">return</SPAN> sgid
sgid <SPAN class="operator token">=</SPAN> extract_sgid<SPAN class="punctuation token">(</SPAN>input_sgid<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># function to export map document to jpeg based on sgid</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">vandv_ddp_jpegs</SPAN><SPAN class="punctuation token">(</SPAN>input_mxd<SPAN class="punctuation token">,</SPAN> sgid<SPAN class="punctuation token">,</SPAN> output_folder<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">""" export map document to jpeg based on sgid """</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>input_mxd<SPAN class="punctuation token">)</SPAN>
df <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
lyrs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> df<SPAN class="punctuation token">)</SPAN>
elm_title <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayoutElements<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT_ELEMENT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"sgkey"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
sqlquery <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0} = {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SGID"</SPAN><SPAN class="punctuation token">,</SPAN> sgid<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Cadastre_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> sqlquery<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Cadastre_lyr"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SGID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> scur1<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># @UndefinedVariable</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> scur1<SPAN class="punctuation token">:</SPAN>
elm_title<SPAN class="punctuation token">.</SPAN>text <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
SGID <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
def_query1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0} = {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SGID"</SPAN><SPAN class="punctuation token">,</SPAN> SGID<SPAN class="punctuation token">)</SPAN>
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> def_query1
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> def_query1
df<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent
df<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>math<SPAN class="punctuation token">.</SPAN>ceil<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">.</SPAN>scale<SPAN class="operator token">/</SPAN><SPAN class="number token">5000</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN><SPAN class="number token">5000</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
output_jpeg <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0}\\{1}.jpg"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>output_folder<SPAN class="punctuation token">,</SPAN> SGID<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Exporting SGID {0} jpeg"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>SGID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ExportToJPEG<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> output_jpeg<SPAN class="punctuation token">,</SPAN> resolution<SPAN class="operator token">=</SPAN><SPAN class="number token">150</SPAN><SPAN class="punctuation token">)</SPAN>
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
lyrs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="keyword token">except</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ExecuteError<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> output_jpeg
output_jpeg <SPAN class="operator token">=</SPAN> vandv_ddp_jpegs<SPAN class="punctuation token">(</SPAN>input_mxd<SPAN class="punctuation token">,</SPAN> sgid<SPAN class="punctuation token">,</SPAN> output_folder<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Any suggestions to achieve the following will be appreciated as I've never done the following before. Will the following accept the incoming url from the SSRS request and return the url path to the output jpeg.