The first part can be found
here .
Update
You need to update both the collector itself and its plugins. The settings page is located at
127.0.0.1:4242/manage (adjusted for its settings). In the case of a new version of the page will hang a button with a proposal to update. I recommend to still download the latest version by yourself, then gently turn off the collector, replace the
jenkins.war file and restart it.
When updating
jenkins.war , an error may occur, so the old file is backed up just in case. Why? First, the files appear on the Japanese server (the author of the assembler is an ordinary Japanese engineer, read more
here ), then they are distributed through the mirrors. References:
You can configure plug-ins on
127.0.0.1:4242/pluginManager/ . More information about plugins will be in the appropriate section, but I recommend updating the existing ones.
Primary setup of the collector
Projects under
Unity are not going in parallel.
BUTYoungSkipper wrote what you can. After reading the documentation there was a desire to try - I will describe the changes in the next article, then edit the paragraph.
That is, only one build on one computer can be run at a time. By default,
Jenkins creates one collector with several implementers, which is not good. Go to the graphical interface or directly to
127.0.0.1:4242/computer/(master)/configure in the settings and change the "
Number of executing processes " to 1.
')
If desired, it is possible to raise assemblies on other machines (for example, leave the apple assemblies here, and transfer them to the
Windows computer for other platforms). We will not consider this opportunity here.
Here -
127.0.0.1:4242/configure - general settings section. Change the following parameters:
- Check that the home directory is correct. For example, / Users / jenkins / WORK / JENKINS_HOME
- Expand advanced settings. Workspace Root Directory is the place where Unity projects should be placed. The " root directory of the build entry " is the repository of the builds. I recommend changing the default values by removing both folders from JENKINS_HOME . For example, in / Users / jenkins / WORK / JENKINS_WORKSPACE / $ {ITEM_FULL_NAME} and in / Users / jenkins / WORK / JENKINS_BUILDS / $ {ITEM_FULL_NAME} .
- "The number of collectors " set, as before, in 1.
- " Delay before assembly " set, for example, in 60 seconds. Useful to undo an incorrect or accidentally running build.
- To build for Android, you may need different JDKs . In the corresponding section, write the names and paths (unchecking the automatic installation). For example, jdk_1.8.0_60 has JAVA_HOME in /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home . This item is optional, only with a strong desire to use different JDK during assembly.
- In the Jenkins Location section, you can specify the address of the collector (in the local network, for example http://192.168.3.69:4242/ ) and the mail of the administrator. Required for some plugins.
- In the Subversion section, if you have the latest plugin updates, you can select the latest version of SVN . For example, 1.8 . The version must match the one installed in the system (up to the first two characters), otherwise it will not be possible to manually edit the project that was automatically created by the builder. See the link to install the required version in the last article .
Jenkins CLI
We should also mention the list of remote commands of the collector. All the necessary information here -
http://127.0.0.1:4242/cli/ . Download
jenkins-cli.jar and using, for example, the following command:
java -jar jenkins-cli.jar -s http://192.168.3.69:4242/ safe-shutdown
it is possible to chop off the assembler from the console from any computer in the local network (all running assemblies will automatically finish first). If you wish, you can prepare the appropriate scripts, but with a hung collector, they may not work.
Plugins
Additional functionality of the collector is supplied by plug-ins. You can configure (install, update, roll back, delete) them in the appropriate section -
127.0.0.1:4242/pluginManager/installed . The complete list is near, the official wiki is
here . Vital below (the rest is better to just update, but it’s unlikely to work directly with them):
- Credentials Plugin - allows you to store passwords. For example, for the SVN repository. In the collector's settings - 127.0.0.1:4242/credential-store/, select Global credentials and create a bunch of username and password for each repository. Parameters - Username and password and Global .
- Subversion Plugin - SVN support. Should already be configured.
Plugins that need to be downloaded to configure build options (some may install related plugins):
- conditional-buildstep - setting the actions of the builder if an error occurred during the build. For example, you can send an email with a log to the administrator or execute a script.
- description setter plugin - create a description of the assembled build based on the build parameters.
- Environment Script Plugin - declaration of internal variables (parameters) of the assembly.
- Extensible Choice Parameter plugin - storing the build parameters in a separate file, for example in the same SVN , after the update from the repository the latest version of settings will be applied.
- Groovy Postbuild - creating a simple script that handles the success of the assembly.
Plugins that change the appearance of the collector and simplify access:
- Extra Columns Plugin - additional columns in the task list. They contain buttons to stop, start a task, and so on.
- Safe Restart Plugin - button to restart the collector directly in the graphical interface.
- Custom Job Icon plugin - assigns each task its own specific icon. For example, you can put the icon of the desired application or platform under which the assembly is. The Custom icons item will appear in the settings, where you can upload your icons. They will be stored in / Users / jenkins / WORK / JENKINS_HOME / userContent / . When loading, the icon shrinks to 64x64, so we are looking for a prettier one.
Unity plugins:
- Unity3d plugin - a plugin that integrates the call of the Unity editor into the assembly. With a strong desire, you can do without it (write all the commands on the command line). After installation, the Unity3d item will appear in the collector settings, in which you can enter a list of installed editors. For example, create a Unity_4_6_8_f1 field with the value /Applications/Unity_4_6_8_f1/Unity.app . It will be used, for example, for test builds. As the main version we use Unity_4_6_6_f2 and a similarly configured path. In order not to update the path to the current version in each task of the collector after the transition to the new one, we create Unity_Default with the necessary parameters.
- Log Parser Plugin - analyzes the output to the log and displays notes and errors. In the collector settings, look for the Console Output Parsing item at the end and create unity_rules with the path to the rule file. Source can be found here or below.
logpareser.rulesstart / ^ Initialize mono /
start / ^ Mono dependencies included in the build /
start / ^ Textures /
info / ^ Complete size /
start / ^ ----- CompilerOutput: -stdout /
info / ^ Compilation succeeded /
start / ^ Used Assets, sorted by uncompressed size /
info / ^ \ * \ * /
info / ^ Exiting batchmode successfully now /
start / ^ === BUILD NATIVE TARGET /
start / ^ Packaging IPA /
start / ^ Archiving artifacts /
start / Uploading to testflight /
warning / error CS02446 /
error / ^ Error building Player /
error / ^ Failed to compile /
error / ^ Error: /
error / ^ error: /
error /: error CS /
warning / ^ Warning: /
warning / ^ WARNING: /
error / ^ xcodebuild: error: /
warning / Debug: LogWarning /
error / There was an error /
error / \ * \ * \ * Canceled /
error / ^ FATAL: /
error / ^ Fatal error /
error / ^ ERROR: /
error / syntax error /
error /^UnityEngine.Debug:LogError/
error /^System.Exception:/
Project structure
- Set up a repository.
- Customize file with parameters.
- Customize the build platform.
- Configure whether to launch Unity or not.
- Download data from the repository.
- If Unity is configured to run, build a fresh build.
- Save build results to archive.
- Run the script depending on the results of the assembly (for example, voice alarm).
Creating a Task (Job Item)
- On the main page of the collector we find the Create Item button. In the parameters, select the task with a free configuration . For the name, select something like projectName_platform . By changing the second part for different tasks, you can set up a simple filter by project later. Go directly to the settings.
- Since it is planned to use the same resources for several tasks, the first thing we do is change the place of the project. We are looking for " Advanced project settings ", select " Use another directory " and enter something like ../JENKINS_WORKSPACE/projectName_standalone . Then we return to the beginning of the settings.
- " Delete obsolete assemblies " - select the desired option. For example, keep only the last few.
- If the plugin has been installed on the user icon and the icons are loaded, select the one you need.
- " This is a parameterized build " - configure this parameter. This requires the Extensible Choice plugin installed earlier. The template is as follows - a parameter of this type is added, its name is entered, it is selected where it will be read from. The data can be stored in an external file (then select the System Groovy Choice Parameter and create a data reading script) or enter it in the Extensible Choice: Available Choice Providers section beforehand in the settings. Here we use the first option. Important! In all parameters, you need to pre-select the default option. But it will be available only after saving the script and re-opening the settings page.
- Setup repositories. Create parameter REPOSITORY . We enter all available in an external file, for example in /Users/jenkins/WORK/repositories.txt . Then we drive in the script:
String _file="/Users/jenkins/WORK/repositories.txt"; ArrayList _list=[]; FileReader _reader = new FileReader(_file); String _line = null; while( ( _line = _reader.readLine() ) != null ) { _list << _line; } return _list.sort();
- Choosing an assembly platform. We create PLATFORM , the script differs only in the name of the external file. Below is a list of platforms for version 4.6:
unity_platforms.txtWebplayer
WebPlayerStreamed
StandaloneOSXIntel
StandaloneOSXIntel64
StandaloneOSXUniversal
StandaloneWindows
iphone
PS3
Xbox360
Android
Standalonelinux
StandaloneLinux64
StandaloneLinuxUniversal
FlashPlayer
StandaloneWindows64
WP8Player
Tizen
PSP2
PS4
PSM
Xboxone
SamsungTV
- The choice of the settings file is PRESET .
import hudson.*; import hudson.model.*; ArrayList _list=[]; _list << ""; FilePath _wp = new FilePath(new FilePath(jenkins.root),project.getCustomWorkspace()); hudson.FilePath _dir = _wp.child("Assets/BuildPresets/"); if (_dir.exists() == false) return _list; hudson.FilePath[] _files = _dir.list("*.asset") for (hudson.FilePath _file : _files) { if (_file.isDirectory() == false) {
For this script, enable the check box Use predefined variables in scripts , which allows you to contact the collector. The code resembles Java , documentation can be found here - http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html . The getCustomWorkspace function provides access to the location specified earlier. If you use the default template, you will have to explicitly enter the path.
- Create parameter BUILD_UNITY . For it, we separately select the Textarea Choice Parameter , where we enter TRUE and FALSE values in two lines.
- Customize " Source Code Management ". Choose Subversion , enter $ {REPOSITORY} as the address, infinite depth, choose a login and password for access (or create, if not already done). When assembling, an explicit value from the file will be substituted for the entered expression As a strategy, select " revert first, then update ".
- Customize the Assembly Triggers . You can collect a task periodically, once a day, for example, only after new versions appear in the repository. For example, “H * / 8 * * *” in the Poll field of the SCM about changes starts the build 3 times a day if there is a fresh version. Next to the menu there is a syntax description help.
Details on setting up other build options here . It must be remembered that if the build is oriented to the latest version in the repository and the repository was selected in the settings that is different from the default one, if the default is changed, the build will not be done! The solution is to manually switch the next assembly or configure the assembly by trigger or by schedule.
- Go to the Post-Assembly section at the end and add the Groovy Postbuild step. The simplest script that analyzes build success is below:
String proc = "/bin/sh /Users/jenkins/WORK/build-failure.sh"; if (manager.build.getResult() == hudson.model.Result.SUCCESS) proc = "/bin/sh /Users/jenkins/WORK/build-success.sh"; proc.execute();
As an error script, for example, you can use:
say "Kill all humans"
- At this stage, save the settings and run the assembly. A directory should be created, a project from the repository is downloaded into it, at the end of the task - to work out one of the scripts. In case of errors, we check whether all the files used in the scripts have been created and whether they have the correct access rights.
- If everything works, go back to the middle of the settings sheet. Select " Generate environment variables from script " and enter something like:
BUILD_SUBDIR=`awk -F: '/location:/ {sub(/.*location: */,""); gsub(/\\\\/,"/"); print}' Assets/BuildPresets/${PRESET}.asset` BUILD_DIR="${WORKSPACE}/${BUILD_SUBDIR}" BUILD_VERSION=`../svnversion -c . | cut -f2 -d:` APPLICATION_NAME=`awk -F: '/buildName:/ {sub(/.*buildName: */,""); gsub(/\\\\/,"/"); print}' Assets/BuildPresets/${PRESET}.asset` BUILD_ARTIFACT=${APPLICATION_NAME}-${PRESET}-${BUILD_VERSION}.zip echo BUILD_SUBDIR=${BUILD_SUBDIR} echo BUILD_DIR=${BUILD_DIR} echo BUILD_VERSION=${BUILD_VERSION} echo APPLICATION_NAME=${APPLICATION_NAME} echo BUILD_ARTIFACT=${BUILD_ARTIFACT}
The first part of the script uses the build parameters to generate additional variables. For example, search for the exact assembly directory and application name from the settings selected in the PRESET file. The svnversion file is put in the WORK folder, and by calling it you can get detailed information about the build. All paths are relative from the current directory.
The second part is specifically for the assembly process. As written in the help, to integrate the variables directly into the assembly, you must send them to / stdout in this format.
- Go to the Build section and create the Conditional steps (multiple) build step. In the launch condition, select the condition of equality of the rows and make a check for the equality $ {BUILD_UNITY} in one field and TRUE in the other. All further steps are performed in this section. This procedure allows you to run the task only to update the data.
- Add a step with the shell commands. Before assembly, you need to clean the assembly directory - use certain variables:
rm -rf "$BUILD_DIR" || true mkdir -p "$BUILD_DIR" || true
- The next step is Invoke Unity3D Editor . In the parameters we specify Unity_Default or a specific version. The build parameters are:
-quit -batchmode -executeMethod Build.CmdBuild -buildPreset=$PRESET -switchBuildTarget=$PLATFORM
Most teams can be found in the official help here . The last 2 parameters are specifically for the build script, but standard -buildOSXPlayer can be used if there are no specific options. Examples of scripts and arguments can be found in the information about the Unity3dBuilder Plugin plugin and on the Unity community wiki .
- The final build step is to archive the results. Standard command:
cd `dirname ${BUILD_SUBDIR}` zip -qr "${BUILD_DIR}/${BUILD_ARTIFACT}" `basename ${BUILD_SUBDIR}`
- In the post- assembly section, you can add an Assembly Description . For example, $ {BUILD_VERSION} $ {PRESET} . It will be displayed next to the build in the build history.
- We archive the results of the assembly. You can list all the files, in this example you need to save the collected archive $ {BUILD_SUBDIR} / $ {BUILD_ARTIFACT} . If you skip this step, you will not be able to download the build results. If auto-cleaning results are specified in the settings, then only a few of them will be available.
- The very last step is parsing logs with the rules for Unity . After that, the task for one platform is completely ready.
Creating a new task
In the example above, the task was configured to build under
Mac . Since the build under
Windows and
Linux can run on the same project without re-importing resources, you can use the same build directory. To do this, we create a new task, as the type we select a copy of an existing one, in the settings we change only the icon, the name of the task, the default platform (the directory remains old!).
In the
View settings, you can create a filter for tasks and display the necessary information about assemblies on the main page. As a result, you might get something like:

Build Android builds
In the first part, references were made to the
JDK and
JRE -
here . Actually,
Java is needed for the normal functioning of the collector. To fully build
Android builds, you need to
download and configure the
Android SDK .
To work correctly, you need to open the
Unity editor under the
jenkins user, go to
Unity / Preferences / External Tools and set up the path to the
Android SDK . In new versions, you also need to specify the path to the
JDK , in the old ones this field is absent. An example of a working configuration:
- OS X 10.10.5
- jdk-8u60-macosx-x64
- Android SDK: Tools 24.3.4
- Android SDK: Platform-tools 23.0.1
- Android SDK: Build-tools 23.0.1
- Android SDK: SDK Platform API 23
- Unity 4.6.6f2
- Android SDK Location: "/ Users / jenkins / WORK / AndroidSDK"
- JDK Location: "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/"
Important! Each version of the editor should be configured (3.xx 4.xx and 5.xx have different configuration files) and under each user under which the build will take place (just under
jenkins ).
To create a new task in the collector, you can copy any
Standalone task. At the same time,
Custom Workspace Directory should be changed - the time for re-importing resources for another platform can be very large, so for
Android builds we create a separate directory for the project. We change the configuration file, the build platform, the task icon. Differences can also be in saved assembly files, for example, you can not archive the result, but save
$ {BUILD_SUBDIR} / *. Apk, $ {BUILD_SUBDIR} / *. Obb files.
No way to change build tools. For example, you need to build under different versions of
Unity of the same, 4th generation, but with different
JDK and
AndroidSDK settings . You can add assembly steps that edit the
~ jenkins / Library / Preferences / com.unity3d.UnityEditor4.x.plist file (use the
defaults shell command), as well as install the
JDK Parameter Plugin and parameterize the assembly with a
JDK selection.
If someone does this - please unsubscribe about the results - I will include it in the article.Important! When updating the
Android SDK, you must rebuild all
Java Plugines written for the project. As they say on the
site : when building, you should include
-source 1.6 -target 1.6 in the assembly line.
Update 10/13/15
- Note YoungSkipper builds several builds at the same time. I will try to implement and edit in case of success, however macmini may not pull.
Update 10/20/15
- Moved Android - instructions in this article, since the article on the assembly for iOS is too big.
- Slightly edited design.