📜 ⬆️ ⬇️

Building Unity3D builds on Jenkins on Mac OS X. Part 2

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.
BUT
YoungSkipper 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:

  1. Check that the home directory is correct. For example, / Users / jenkins / WORK / JENKINS_HOME
  2. 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} .
  3. "The number of collectors " set, as before, in 1.
  4. " Delay before assembly " set, for example, in 60 seconds. Useful to undo an incorrect or accidentally running build.
  5. 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.
  6. 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.
  7. 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):



Plugins that need to be downloaded to configure build options (some may install related plugins):



Plugins that change the appearance of the collector and simplify access:



Unity plugins:



Project structure


  1. Set up a repository.
  2. Customize file with parameters.
  3. Customize the build platform.
  4. Configure whether to launch Unity or not.
  5. Download data from the repository.
  6. If Unity is configured to run, build a fresh build.
  7. Save build results to archive.
  8. Run the script depending on the results of the assembly (for example, voice alarm).


Creating a Task (Job Item)


  1. 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.

  2. 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.

  3. " Delete obsolete assemblies " - select the desired option. For example, keep only the last few.

  4. If the plugin has been installed on the user icon and the icons are loaded, select the one you need.

  5. " 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.

  6. 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(); 

  7. 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.txt
    Webplayer
    WebPlayerStreamed
    StandaloneOSXIntel
    StandaloneOSXIntel64
    StandaloneOSXUniversal
    StandaloneWindows
    iphone
    PS3
    Xbox360
    Android
    Standalonelinux
    StandaloneLinux64
    StandaloneLinuxUniversal
    FlashPlayer
    StandaloneWindows64
    WP8Player
    Tizen
    PSP2
    PS4
    PSM
    Xboxone
    SamsungTV

  8. 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) { //_list << _file.getName(); _list << _file.getBaseName(); } } return _list.sort(); 

    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.

  9. Create parameter BUILD_UNITY . For it, we separately select the Textarea Choice Parameter , where we enter TRUE and FALSE values ​​in two lines.

  10. 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 ".

  11. 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.

  12. 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" 

  13. 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.

  14. 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.

  15. 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.

  16. 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 

  17. 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 .

  18. The final build step is to archive the results. Standard command:

     cd `dirname ${BUILD_SUBDIR}` zip -qr "${BUILD_DIR}/${BUILD_ARTIFACT}" `basename ${BUILD_SUBDIR}` 

  19. 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.

  20. 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.

  21. 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:

image

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:


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

  1. 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

  1. Moved Android - instructions in this article, since the article on the assembly for iOS is too big.
  2. Slightly edited design.

Source: https://habr.com/ru/post/268365/


All Articles