You can automate map service publishing in a Python script. To do this, you need to call the following sequence of functions from the arcpy.mapping module and tools from the Server toolbox.
- Use the arcpy.mapping function CreateMapSDDraft to create a draft service definition (.sddraft). This function reads your map document (MXD) and creates the draft service definition.
- Use the arcpy.mapping function AnalyzeForSD to analyze your draft service definition for errors that might prevent its publishing. This function returns a Python list of errors, warnings, and informational messages that can help you validate whether your map is ready for publishing. This list is similar to what you get when you click the Analyze button from the Service Editor dialog box in ArcGIS Desktop.
- Run the Stage Service geoprocessing tool on your draft service definition. This converts your draft into a service definition (.sd) that is ready to publish to ArcGIS Server.
- Run the Upload Service Definition geoprocessing tool to publish your service definition as a service.