ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Upload Service Definition

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Uploads and publishes a GIS service to a specified GIS server based on a staged service definition file (.sd).

Usage

  • This tool uploads and publishes a GIS service based on the input service definition. Whenever you share a service using ArcGIS Desktop, this tool is run, and you will see a result in the geoprocessing Results window.

  • This tool does not upload and publish service definition draft files (.sddraft). If you have a service definition draft file, you can convert it to a staged service definition file using the Stage Service tool.

  • You can use the Sign In To Portal tool to connect to an ArcGIS Online portal.

Syntax

arcpy.server.UploadServiceDefinition(in_sd_file, in_server, {in_service_name}, {in_cluster}, {in_folder_type}, {in_folder}, {in_startupType}, {in_override}, {in_my_contents}, {in_public}, {in_organization}, {in_groups})
ParameterExplanationData Type
in_sd_file

The service definition file (.sd) that contains all the information needed to publish a GIS service.

File
in_server

The server connection. You can use the ArcGIS Server connections listed under the GIS Servers node in the Catalog window, or you can browse to a folder where you store server connection files.

If you are connecting to ArcGIS Online, make sure you type My Hosted Services for the server connection with each word capitalized and a space between each word.

ServerConnection
in_service_name
(Optional)

Overrides the service name currently specified in the service definition with a new name.

String
in_cluster
(Optional)

Changes the cluster to which the service has been assigned. You must choose from clusters that are available on the specified server.

Legacy:

Clusters are deprecated at ArcGIS Enterprise 10.5.1. This parameter will be ignored by servers that do not support multiple clusters.

String
in_folder_type
(Optional)

Specifies the source for the folder. The default is a folder from the service definition. You can also choose a folder already existing on the specified server or a new folder to be created once you publish this service.

  • NEW —Use this to create a new folder.
  • EXISTING —Use this to specify a folder that exists on the server.
  • FROM_SERVICE_DEFINITION —Use the folder already specified in the service definition. This is the default.
String
in_folder
(Optional)

The folder for the service. The default is the folder specified in the service definition. If you chose NEW for the folder type, provide a new folder name. If you chose EXISTING for the folder type, choose an existing folder on the server.

String
in_startupType
(Optional)

Specifies the start state of the service immediately after publishing.

  • STARTED —The service starts immediately after publishing.
  • STOPPED —The service does not start after publishing. You must start the service manually.
Boolean
in_override
(Optional)

Specifies whether the sharing properties set in the service definition will be overridden. These properties define if, and how, you are sharing your service with ArcGIS Online. Sharing your service with ArcGIS Online exposes it for others to use.

  • OVERRIDE_DEFINITION —The sharing properties set in the service definition will be overridden with new values.
  • USE_DEFINITION —The sharing properties currently set in the service definition will be used when the service is published. This is the default.

You must be logged in to ArcGIS Online in order to override sharing properties.

Boolean
in_my_contents
(Optional)

Specifies whether the service will be shared on ArcGIS Online. All shared services are available through My Contents. Even if you only want to share with a specific group in your organization, the service will also be shared through My Contents.

  • SHARE_ONLINE —The service will be shared on ArcGIS Online. The service will be listed under My Content.
  • NO_SHARE_ONLINE —The service will not be shared on ArcGIS Online and will be inaccessible to other ArcGIS Online users and clients on the web.

You must be logged in to ArcGIS Online in order to override sharing properties.

Boolean
in_public
(Optional)

Specifies whether the service will be available to the public.

  • PUBLIC —The service will be shared with the public.
  • PRIVATE —The service will not be shared with the public.

You must be signed in to ArcGIS Online to override sharing properties.

Boolean
in_organization
(Optional)

Specifies whether the service will be shared with your organization.

  • SHARE_ORGANIZATION —The service will be shared with your organization.
  • NO_SHARE_ORGANIZATION —The service will not be shared with your organization.

You must be signed in to ArcGIS Online to override sharing properties.

Boolean
in_groups
[group_name,...]
(Optional)

A list of group names with which the service will be shared.

You must be signed in to ArcGIS Online to override sharing properties.

String

Code sample

UploadServiceDefinition example (Python window)

Upload and publish a service definition to a specified server.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.UploadServiceDefinition_server("myMapService.sd", "GIS Servers/myServerConnection")
Publishing workflow example (stand-alone script)

The following script demonstrates a publishing workflow using the Stage Service and Upload Service Definition tools.

# Name: StageService_UploadServiceDefinition_example2.py
# Description: Use a service definition draft to create a service definition
# and then upload and publish that service definition.
# Requirements: Connection to an ArcGIS Server or My Hosted Services

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Set local variables
inServiceDefinitionDraft = "myMapService.sddraft"
outServiceDefinition = "myMapService.sd"

# Execute StageService
arcpy.StageService_server(inServiceDefinitionDraft, outServiceDefinition)

# Set local variables
inSdFile = outServiceDefinition
inServer = "GIS Servers/myServerConnection"

# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(inSdFile, inServer)
UploadServiceDefinition example 2 (stand-alone script)

The following script loops through all service definitions in a folder and publishes each one to an ArcGIS Server.

# Name: UploadServiceDefinition_example3.py
# Description: Upload and publish all service definitions contained in a folder
# Requirements: Connection to an ArcGIS Server or My Hosted Services

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Set local variable
inServer = "myServerConnection.ags"
print "Publishing to " + inServer

# Find all the service definitions (.sd or .sds) in a workspace and 
# upload\publish each one to an ArcGIS Server, Spaital Data Server, or My Hosted Services
sdList = arcpy.ListFiles("*.sd")
for inSdFile in sdList:
    print "Publishing " + sdName
    try:
        arcpy.UploadServiceDefinition_server(inSdFile, inServer)        
    except Exception, e:
        print e.message
UploadServiceDefinition example 3 (stand-alone script)

The following script uploads an existing service definition and uses optional parameters to modify properties of the service.

# Name: UploadServiceDefinition_example5.py
# Description: Uploads an existing service definition and uses optional 
#              parameters to modify some details of the service
# Requirements: Connection to an ArcGIS Server or My Hosted Services

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Set local variables
inSdFile = "myMapService.sd"
inServer = "myServerConnection.ags"
inServiceName = "newServiceName"
inCluster = "myCluster"
inFolderType = "NEW"
inFolder = "newFolder"
inStartup = "STOPPED"
inOverride = "OVERRIDE_DEFINITION"
inMyContents = "SHARE_ONLINE"
inPublic = "PRIVATE"
inOrganization = "NO_SHARE_ORGANIZATION"
inGroups = "My Group"

# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName, 
                                     inCluster, inFolderType, inFolder, 
                                     inStartup, inOverride, inMyContents, 
                                     inPublic, inOrganization, inGroups)
Overwriting services example (stand-alone script)

The following script creates and uploads a service definition that can be used to overwrite an existing service.

# Name: StageService_example3_UploadServiceDefinition_example4.py
# Description: Creates a service definition that can be used to overwrite an 
#              existing service. When this service definition is published it 
#              will overwrite the existing service.
# Requirements: Connection to an ArcGIS Server, Spatial Data Server, 
#               or My Hosted Services


# Import system modules
import arcpy
import xml.dom.minidom as DOM 

# Set environment settings
arcpy.env.workspace = "C:/data"

# Set local variables
inServiceDefinitionDraft = "myMapService.sddraft"
outServiceDefinition = "myMapService.sd"
newType = 'esriServiceDefinitionType_Replacement'

xml = os.path.join(arcpy.env.workspace, inServiceDefinitionDraft)
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
    if desc.parentNode.tagName == 'SVCManifest':
        if desc.hasChildNodes():
            desc.firstChild.data = newType
outXml = xml    
f = open(outXml, 'w')     
doc.writexml( f )     
f.close()

# Execute StageService
arcpy.StageService_server(inServiceDefinitionDraft, outServiceDefinition)

# Set local variables
inSdFile = outServiceDefinition
inServer = "GIS Servers/myServerConnection"

# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(inSdFile, inServer)

Environments

This tool does not use any geoprocessing environments.

Licensing information

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

Related topics

  • An overview of the Publishing toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal