Map deploy with Python and Jenkins

2548
2
03-07-2016 04:48 PM
RobertPotter
New Contributor II

I have a great little Python script that works fabulously to deploy map services and register data sources.  It works well on my PC, in Pyscripter and from the command line but only works in Pyscripter on the server, where I wish to have a Jenkins job do the deployment.

When run from the command line on the server it returns "Cannot connect to database", in Pyscripter it just works.

If anyone has a clue why this could be, it does not appear to be a user and permission issue.

Output from Pyscripter:

Command Line : DEV

The following information was returned during analysis of the MXD:

----MESSAGES---

     Layer draws at all scale ranges  (CODE 30003)

       applies to: Bid Points Bid Lines Bid Points Bid Lines

----WARNINGS---

----ERRORS---

Service BIDS, successfully published

Executing: UploadServiceDefinition "C:\Program Files (x86)\Jenkins\workspace\MAP-DEPLOY\MXD\BIDS.sd" "C:\Program Files (x86)\Jenkins\workspace\MAP-DEPLOY\MXD\serverconnection.ags" # # FROM_SERVICE_DEFINITION # STARTED USE_DEFINITION NO_SHARE_ONLINE PRIVATE NO_SHARE_ORGANIZATION #

Start Time: Fri Mar 18 13:40:44 2016

Submitted.

Executing...

Executing (Publish Service Definition): PublishServiceDefinition i6cdf6dfc-7490-426c-a096-4f8e77852141 # {"buildInitialCache":false} #

Start Time: Fri Mar 18 13:40:45 2016

Validating publish options.

Connecting to the server.

Getting basic item metadata for service definition upload.

Getting server information (server folders, data stores, etc.).

Extracting manifiest from uploaded service definition.

Deriving arcgis server service from hosted service (hosted service definition).

Validating service definition.

Determining service's input folder name.

Attempt to find service's input folder.

Creating the service.

Adding item information card to service.

Updating file and folder information in service's manifest.

Updating database information in service's manifest.

Adding manifest to configuration store.

Building the service URLs.

Succeeded at Fri Mar 18 13:41:17 2016 (Elapsed Time: 32.17 seconds)

Succeeded.

Succeeded at Fri Mar 18 13:41:17 2016 (Elapsed Time: 33.10 seconds)

Output from Command line:

C:\Program Files (x86)\Jenkins\workspace\MAP-DEPLOY>python MXD\Deploy_MXD.py DEV

Cannot open server connection to database.

​Also see comments below

Tags (2)
2 Replies
Luke_Pinner
MVP Regular Contributor

Can you narrow it down to a small snippet that generates the error? What database is the script connecting to? Are you using 32 or 64bit PyScripter? When run from the command line on the server, are you running in 64 or 32bit python? Do you have the appropriate database driver installed for 32/64 bit python?

RobertPotter
New Contributor II

Hi and thanks for the great questions!

both the command line and the Pyscripter are Python 2.7.5, win32 on win 32.

the problem seems to come in this function, although prior this step it creates the serverConnection.ags file successfully.

def registerDatabaseWithServer(databaseConnection, arcgisServerAdminConnection, arcgisServerDataStoreName):

    dataStoreType = "DATABASE"

    removeRegisteredDataStore(arcgisServerAdminConnection, arcgisServerDataStoreName, dataStoreType)

    arcpy.AddDataStoreItem(arcgisServerAdminConnection, dataStoreType, arcgisServerDataStoreName, databaseConnection, databaseConnection)

I tried putting a try exception, on this and pass if fails and it proceeded through the rest of the deployment except it warns that the datasource was not registered with the server.

I do so really want to get this to work as it will offer a great deal of automation and consistency to our map service publishing.

Thanks for any further advice you can offer

0 Kudos