Stage Service (Server)

Summary

Stages a service definition. A staged service definition file (.sd) contains all the necessary information to share a web layer, locator, web tool, or service.

Usage

  • This tool converts a service definition draft file (.sddraft) to a service definition that can be input to the Upload Service Definition tool to upload and publish a web layer, locator, web tool, or service to ArcGIS Online, ArcGIS Enterprise, or ArcGIS Server. Draft service definitions cannot be used to publish a web layer, locator, web tool, or service directly.

  • This tool will analyze .sddraft files to determine suitability and sources of potential performance issues before converting an .sddraft file to an .sd file. When the tool is running, you can hover over the progress bar to display a pop-up window containing comprehensive information about the tool, including analyzer messages. You can also click View Details to see the same information in a detached window, or click Open History to open the project's geoprocessing history. When the tool is finished running, the progress bar will display an icon and message to indicate the tool status. For more information about viewing messages in geoprocessing tools, see Use a geoprocessing tool.

  • When analyzing an .sddraft file, you may see two types of messages: errors and warnings. Analyzer errors must be addressed before you can create an .sd file. Analyzer warnings identify issues related to performance, appearance, and data access but do not prevent you from converting the .sddraft file to an .sd file. Each analyzer message has an associated help topic. For more information about resolving these issues, see Analyze your GIS resource.

  • Service definition drafts can be created using the arcpy.sharing module or the CreateGeocodeSDDraft or CreateGPSDDraft ArcPy functions.

Parameters

LabelExplanationData Type
Service Definition Draft

The input draft service definition. Service definition drafts can be created using the arcpy.sharing module or the CreateGeocodeSDDraft or CreateGPSDDraft ArcPy functions.

File
Service Definition

The resulting service definition. The default is to write the service definition to the same directory as the draft service definition.

File
Staging Version
(Optional)

The version of the published service definition.

When sharing a feature, a tile, or an imagery layer to ArcGIS Enterprise, use 5 for the value. When sharing a map image layer or web tool to ArcGIS Enterprise, and any layer type to ArcGIS Online, use 102 for the value. This is the default.

When sharing a web tool or geoprocessing service to ArcGIS Enterprise or ArcGIS Server using the GeoprocessingSharingDraft or CreateGPSDDraft function, use the value corresponding to the version number from the following list:

  • 11.3--330
  • 11.2—320
  • 11.1—310
  • 11.0—300
  • 10.9.1—209
  • 10.9—208
  • 10.8.1—206
  • 10.8—205
  • 10.7.1—204
  • 10.7—203
  • 10.6.1—202
  • 10.6—201
  • 10.5.1—200
Long

arcpy.server.StageService(in_service_definition_draft, out_service_definition, {staging_version})
NameExplanationData Type
in_service_definition_draft

The input draft service definition. Service definition drafts can be created using the arcpy.sharing module or the CreateGeocodeSDDraft or CreateGPSDDraft ArcPy functions.

File
out_service_definition

The resulting service definition. The default is to write the service definition to the same directory as the draft service definition.

File
staging_version
(Optional)

The version of the published service definition.

When sharing a feature, a tile, or an imagery layer to ArcGIS Enterprise, use 5 for the value. When sharing a map image layer or web tool to ArcGIS Enterprise, and any layer type to ArcGIS Online, use 102 for the value. This is the default.

When sharing a web tool or geoprocessing service to ArcGIS Enterprise or ArcGIS Server using the GeoprocessingSharingDraft or CreateGPSDDraft function, use the value corresponding to the version number from the following list:

  • 11.3--330
  • 11.2—320
  • 11.1—310
  • 11.0—300
  • 10.9.1—209
  • 10.9—208
  • 10.8.1—206
  • 10.8—205
  • 10.7.1—204
  • 10.7—203
  • 10.6.1—202
  • 10.6—201
  • 10.5.1—200
Long

Code sample

StageService example 1 (stand-alone script)

The following script publishes a list of layers from a map as a web tile layer to either ArcGIS Enterprise or ArcGIS Online. Portal information is obtained from the Portals page in ArcGIS Pro.

import arcpy
import os

# Set output file names
outdir = r"C:\Project\Output"
service = "TileSharingDraftExample"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps("World")[0]
lyrs = []
lyrs.append(m.listLayers('cities')[0])
lyrs.append(m.listLayers('counties')[0])

# Create TileSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "TILE", service, lyrs)
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"
sharing_draft.credits = "My Credits"
sharing_draft.useLimitations = "My Use Limitations"

# Create Service Definition Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)

# Stage Service
sd_filename = service + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Uploading Service Definition...")
arcpy.server.UploadServiceDefinition(sd_output_filename, "My Hosted Services")

print("Successfully Uploaded service.")
StageService example 2 (stand-alone script)

The following script stages an existing service definition draft and displays analyzer warnings and errors.

import arcpy

try:
    arcpy.server.StageService(r"C:\Data\World.sddraft", r"C:\Data\World.sd")
    warnings = arcpy.GetMessages(1)
    print(warnings)

except Exception as stage_exception:
    print("Sddraft not staged. Analyzer errors encountered - {}".format(str(stage_exception)))

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics