Skip To Content

Stage Service

Summary

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

Usage

  • This tool converts a service definition draft (.sddraft) into a service definition that can then be input to the Upload Service Definition tool to upload and publish a web layer to a hosted server. Draft service definitions cannot be used to publish a web layer directly.

  • Whenever you share a web layer using ArcGIS Pro, the Stage Service tool is run, and you will see an entry in the Geoprocessing History item in the Catalog pane.

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

Syntax

StageService_server (in_service_definition_draft, out_service_definition, staging_version)
ParameterExplanationData Type
in_service_definition_draft

Input draft service definition. Service definition drafts can be created using the arcpy.sharing module, or the CreateImageSDDraft or CreateGPSDDraft ArcPy functions..

File
out_service_definition

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

File
staging_version

Version of the service that the service definition will be published as.

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

Long

Code sample

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, 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 Defintion Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)

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

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

print("Successfully Uploaded service.")

Environments

Licensing information

  • ArcGIS Desktop Basic: Yes
  • ArcGIS Desktop Standard: Yes
  • ArcGIS Desktop Advanced: Yes

Related topics