Mobile Center with Azure Pipelines

Mobile Center with Azure Pipelines

Challenge

It is possible to integrate Mobile Center with Azure DevOps Pipelines? Or any other hosted CI/CD service?

Diagnosis

When using CI/CD cloud/hosted services, it is becomes an obvious that the generated artefacts should be published for Continuous Testing. How this can be achieved with Mobile Center, which is not part of any of those solutions?

Solution

Mobile Center has a REST API, which can be used to integrate in Azure Pipelines.

However, the REST API scripting in Azure Pipelines is very basic (support only basic authentication, no option to pass parameters between the REST API requests, etc.)

The most elegant solution in this case can be use of Python program or bash script.

Here is the flow:

1. In the example below, the pipeline generates and export the artefact for iOS app in IPA format.  Please be sure to use correct signing method for the IPA. The export task example:

- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)/myApp.ipa'
artifactName: 'myApp'

 

2. Create a task that will install pre-requisite for Python ('requests' module)

- task: Bash@3
inputs:
targetType: 'inline'
script:
python -m pip install --upgrade pip requests
 
3. Add Python script to your code repository (save, for instance, to root directory as 'mc-uploadApp.py')
import sys,json, requests
PROTOCOL = 'http'
PORT = '8080'

SERVER = sys.argv[1]
USER = sys.argv[2]
PASS = sys.argv[3]
FILE = sys.argv[4]

BASE_URL = PROTOCOL + '://' + SERVER + ':' + PORT + '/rest' 
s = requests.Session() 
# LOGIN 
url = BASE_URL + '/client/login' 
headers = {'Accept': 'application/json' , 'Content-Type': 'application/json; charset=UTF-8'} 
payload = {'name': USER , 'password': PASS , 'accountName': 'default'} 
response = s.post(url, headers=headers, data=json.dumps(payload)) 
print ("Connect: ", response.status_code)

hp4msecret = response.headers['x-hp4msecret']
jsession = s.cookies['JSESSIONID']


if response.status_code == requests.codes.ok: 
# UPLOAD APP 
    url = BASE_URL + '/apps' 
    file = {'fileUpload': open(FILE, 'rb')} 
    headers = {'x-hp4msecret': hp4msecret, 'JSESSIONID': jsession} 
    response = s.post(url, headers=headers, files=file) 
    print ("Upload: ", response.status_code) 

if response.status_code == requests.codes.ok: 
    print ("App Name:", response.json()["name"]) 
    print ("App Id:", response.json()["id"]) 
    print ("App version:", response.json()["version"]) 
    #print ("App Count:", response.json()["count"]) 
 
4. Add Python script task that will use the generated IPA/APK file and upload to Mobile Center:

      - task: PythonScript@0
        inputs:
          scriptSource: 'filePath'
          scriptPath: 'mc-uploadApp.py'
          arguments: '   $(agent.buildDirectory)/output/$(sdk)/$(configuration)/myApp.ipa'

 

Run the pipeline - the IPA should be generated and uploaded to Mobile Center.

Enjoy!

Labels (1)

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
4 of 4
Last update:
‎2020-02-03 21:38
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.