It look like publishing feature service from a .sd-file doesn't take into account publish_parameters provided as a parameter. If I use geodatabase instead, it seems to work as expected. I assume that this is a bug in the API but does someone know if there is workaround with .sd files? The idea behind the script is that we would like to publish different versions (ie. -dev, -qa) of the service as part of our DevOps pipeline from the same service. Geodatabases seems to work but it doesn't support symbology out of the box.
My test workflow here is very simple:
- upload .sd file
- publish with "GeoChatTest" and custom "Description"
- publish with "GeoChatTest2" and custom "Description"
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">import</SPAN> getpass
password <SPAN class="operator token">=</SPAN> getpass<SPAN class="punctuation token">.</SPAN>getpass<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Enter password: "</SPAN><SPAN class="punctuation token">)</SPAN>
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'organization'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Connected to: {}\nConnected as: {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>
gis<SPAN class="punctuation token">.</SPAN>properties<SPAN class="punctuation token">.</SPAN>urlKey <SPAN class="operator token">+</SPAN> <SPAN class="string token">"."</SPAN> <SPAN class="operator token">+</SPAN> gis<SPAN class="punctuation token">.</SPAN>properties<SPAN class="punctuation token">.</SPAN>customBaseUrl<SPAN class="punctuation token">,</SPAN>
gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me<SPAN class="punctuation token">.</SPAN>username<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
folder_name <SPAN class="operator token">=</SPAN> <SPAN class="string token">'GeoChatTest'</SPAN>
folder <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>create_folder<SPAN class="punctuation token">(</SPAN>folder<SPAN class="operator token">=</SPAN>folder_name<SPAN class="punctuation token">)</SPAN>
folder
uploaded_service_definition_item <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>
item_properties<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'title'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'GeoChat-ServiceDefinition'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'snippet'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Test service definition'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'description'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Test service that is created by using automation.'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'accessInformation'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'licenseInfo'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'For testing purposes only!'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'type'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Service Definition'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'tags'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'chat'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'geochat'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
folder <SPAN class="operator token">=</SPAN> folder_name<SPAN class="punctuation token">,</SPAN>
thumbnail<SPAN class="operator token">=</SPAN>r<SPAN class="string token">"./data/publishing_data/thumbnail_geochat.png"</SPAN><SPAN class="punctuation token">,</SPAN>
data<SPAN class="operator token">=</SPAN>r<SPAN class="string token">"./data/publishing_data/GeoChat.sd"</SPAN><SPAN class="punctuation token">)</SPAN>
uploaded_service_definition_item
item_properties <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'name'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'GeoChatTest'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'description'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Test 1'</SPAN>
<SPAN class="punctuation token">}</SPAN>
published_feature_service_item <SPAN class="operator token">=</SPAN> uploaded_service_definition_item<SPAN class="punctuation token">.</SPAN>publish<SPAN class="punctuation token">(</SPAN>item_properties<SPAN class="punctuation token">)</SPAN>
published_feature_service_item
item_properties <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'name'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'GeoChatTest2'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'description'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Test 2'</SPAN>
<SPAN class="punctuation token">}</SPAN>
published_feature_service_item <SPAN class="operator token">=</SPAN> uploaded_service_definition_item<SPAN class="punctuation token">.</SPAN>publish<SPAN class="punctuation token">(</SPAN>item_properties<SPAN class="punctuation token">)</SPAN>
published_feature_service_item<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>What actually happens:
- .sd file is uploaded
- Feature Service is created with the name from the .sd file with description from the .sd file as well

- Error on publish: RuntimeError: Service name 'GeoChat' already exists for 'ut5Ig3pyAO7DhCxU'
Atma Mani Andrew Chapkowski thoughts?