Xcode Server is Apple’s own continuous integration service

Xcode Server is an official continuous integration solution provided by Apple. It existed before Xcode 9. However, you need to download and install OS X Server (paid software) from the Mac App Store, which is cumbersome to use. In Xcode 9, Xcode Server is built into Xcode, so the whole CI environment construction process is greatly simplified.

Second, Xcode Server advantages

  • Free 1.
  • 2. Support OTA installation
  • 3. Use the same certificate as manual packaging

3. Tools needed

  • A Mac with Xcode 9.0 or later installed
  • Apple Developer Account

4. Build a basic continuous integration environment

  • Pull formulates the code for a particular branch of the repositoryCopy the code
  • Specifies the conditions that trigger the CICopy the code
  • Perform the Archive operation and export the Ad Hoc signature installation packageCopy the code
  • Upload this installation package to the server for testers to download and installCopy the code

Step 1: Start Xcode Server

Open Xcode->Preferences->Server & Bots, click the switch that shows OFF, enter the administrator password, and select Integration User in the window that pops up. Apple recommends using a specific, non-admin user, but you can also use the currently logged in user. Here, you can directly select the current logged-in user.

After clicking Continue, the Server will be configured and started. Once complete, the following interface will appear:

At this point, Xcode Server is started. The Server can be configured according to your needs, so we don’t need to change any Settings for now.

Step 2, add the Bot

2.1 Open the project in Xcode and go to Product->Create Bot…

To Create a Bot, you must have the project open, otherwise ‘Product->Create Bot… The ‘item is grayed out and cannot be clicked. 2.2 Connecting to the Server

In the pop-up window, you can name the Bot and select ‘Add New Server… ‘. On the Next screen, select Server from the list and click ‘Next’. Then, enter the username, password, and click ‘Add’. 1778459-ebc3acc4afb99981.png

In this case, I have chosen to connect to the Server as a ‘Registered user’ and then enter the username and password of the current logged-in user. Recall that when we started the Server, the Integration User we selected was the current login User. If you select ‘Guest’, that’s fine, but you’ll later find that you can’t edit the Bot you’ve created. The result of this step is essentially creating an Account of type Xcode Server and adding it to Xcode.

2.3 Connecting to the Code Repository

First, your project will use Git. Xcode can read your project’s repository information directly. On the screen below, click Sign In… After logging in with your Git account password, select the specific branch from the drop down box and click Next.

2.4 Setting up the build configuration

Scheme: Select which Scheme to build. The Scheme to be built must be shared. Therefore, if Scheme is unshared, keep ‘Share and commit Scheme ‘selected. Xcode will automatically set Scheme to the shared state.

Actions: Specifies which Actions to perform. There are three classes: Analyze(code static analysis), Test(Test), and Archive(packaging). For Export, select ‘Use Custom Export Options Plist’ because if you Use the default option, the resulting package will always be signed with the iPhone Developer certificate and will not be able to create an ad-hoc package.

Exportoptions. plist can be obtained by manually executing Product->Archive and exporting the ad-hoc installation package. The exported directory contains an exportOptions. plist file, which can be used directly.

2.5 Setting build Triggers

Possible types: periodic build, commit build, manual build. Here we choose to build manually. Below you can check to upgrade Xcode after automatic build. You can also set Clean before each build.

2.6 Selecting a Device Type

Available types: iOS devices and emulators, iOS devices, emulators, here we choose iOS devices

2.7 Configuring signatures and certificates for your server

Options: Check the development team account, if the project is Xcode automatic management certificate and description file, check all of this.

Certificates & Profiles: If manually managed Certificates and description files, select the required ones and click Add to Server to Add them to Xcode Server.

2.8 Configuring Environment Variables

1. The parameters passed to XcodeBuild can be added first. The supported parameters can be queried by terminal type ‘xcodeBuild –help’ 2. You can add custom environment variables that can be used in later scripts 3. You can customize the parameter configuration

2.9 Configuring Triggers

Click the plus sign in the lower left to pop up the menu. Here we can add scripts executed before build, scripts executed after build, and mail-related triggers to modify the configuration in combination with XCodeProJ

Scripts that are executed before the Build will either change the Build number or perform actions related to CocoaPods.

The above script automatically changes the Build number to the current time.

The environment in which the trigger code runs is actually the terminal, and its current directory is one level above the project directory. The script can use the environment variables we added in the previous step, as well as some environment variables defined by Xcode Server. Let’s explain the code above: 1. CD to project directory 2. 3. Commit code to git server

A script executed after the build usually uploads the package to the server, dandelion, etc. Here is our upload script:

#! /bin/sh PRODUCT_PATH="${XCS_PRODUCT}" #! Ipa file path to the location of the WNL_VERSION = ` / usr/libexec/PlistBuddy - c "Print CFBundleShortVersionString" ./Calendar/CalendarOS7/CalendarOS7-Info.plist` #! To obtain the version number filename = "${WNL_VERSION} _ WNL_V ` date + % y H % m % d % % m ` ipa" #! New filename tempPath="Desktop/ TMP "#! Server ="//employee:[email protected]/Documents2"#! Network disk address #! Check whether the network disk has been mounted. If yes, First uninstall drives_to_unmount = ` df | awk '/ [email protected] /} {print $9 ` if [" $drives_to_unmount! "" = "" ] then umount ${drives_to_unmount} fi mkdir -p ~/${tempPath}#! Mount -t SMBFS ${server} ~/${tempPath}# ${tempPath}/ios /${WNL_VERSION}#! Cp ${PRODUCT_PATH} ~/${tempPath}/ios /${WNL_VERSION}/${filename}#! Umount ~/${tempPath}#! Unmount the disk Echo is successfully uploadedCopy the code

When creating a post-build script, you need to choose when to execute it. Here we select compile warning, success, and when all issues are resolved.

Click Done, a basic Bot is configured, and the first Integration starts automatically. At the end of the integration, the packaged IPA file is uploaded to our server.

View the results of integration and manage Bots, Integrations

In Xcode, go to the Report Navigator and select Bot or an integration. In the right window area, you can view integration results, trigger a new integration, save IPA, install IPA, save Archive, display Archive in Organizer. Upload to App Store and manage Bots, such as editing and deleting.

To view the log

Click the triangle menu on the left of Integrate to expand and select Logs to view the log of this integration, including the log of compilation, version control and trigger. When packaging fails, failure causes can be analyzed through these Logs

Access Xcode Server from a browser

The address to access the Xcode Server in the browser is “https://hostname/xcode”, and the hostname can be the IP address, remote hostname of the Server, or local hostname. In the PC browser, you can start integration, download IPA, open it in Xcode, and download Archive. In the mobile browser, you can only develop integration and install IPA.

Access Xcode Server from a browser

The address to access the Xcode Server in the browser is “https://hostname/xcode”, and the hostname can be the IP address, remote hostname of the Server, or local hostname. In the PC browser, you can start integration, download IPA, open it in Xcode, and download Archive. In the mobile browser, you can only develop integration and install IPA.

OTA installation

To use an OTA installation, you must access it using hostname. 1. Click ‘PROFILE’ to install the root certificate of Xcode Server and trust the certificate. 2. Choose Settings > General > About > Certificate Trust Settings to open Xcode Server Root Certificate Authority. 3. Click ‘INSTALL’ to INSTALL the APP. Some directories at build time

/ Library/Developer/XcodeServer/IntegrationAssets: this directory will save all of the Bot every integration as a result, the IPA file, symbol file can be found in the directory. ~ / Library/Caches/XCSBuilder/Bots/XXX / : XXX represents a Bot ID, in the Source directory in the directory, deposit is pulled to the warehouse code.

The pit of common

1. Use a separate Mac as a package server, or once you pack, you won’t be able to type code and you’ll doubt your life.

2. Slow packing. After several observations, I found that packaging has a Process Warning that is very slow. Our project had about 2,500 warnings, but I cut it down to less than 100, and the packaging time went from 30-plus minutes to 10 minutes, cutting the time by two-thirds.

3. The compilation succeeds, but the export fails. Xcode Server cannot automatically generate a profile. Go to the Server to manually generate a profile, and then use Xcode Server to package, you can successfully pass the packaging.

4. Do not change the system time during packaging. This is really pit, Xcode Server can only play one bag at a time, is packaged points when other Bot package, will be displayed in front of an integration is running, to perform up to start packing, if changed the system time in the process of packaging, even in front of a completed package, later also won’t start, can’t restart, You can only reload Xcode.

Refer to the link: www.jianshu.com/p/167fb1dbe…